Jump to content

Forge 1.7.2 [SOLVED] Items taking damage when used in crafting


VikkeHD

Recommended Posts

Hi Forge Users

 

I have search for ages after a tutorial on how to get items to take damage when used in crafting recipe.

 

I know that in older versions of forge i could use CraftingHandler.

But it's been made to an event know.

 

The problem is that i cant find any tutorials on how to make it with events...

 

If anyone know how to do this please help me!

 

-VikkeHD [move]:)[/move]

Link to comment
Share on other sites

Event Class:

package dudesmods.lozmod.lozmod3.proxy;

import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.PlayerEvent;
import dudesmods.lozmod.lozmod3.LOZmod;

public class LOZmodEVENT {

@SubscribeEvent
public void onCrafting(PlayerEvent.ItemCraftedEvent e) {

	for(int i=0; i < e.craftMatrix.getSizeInventory(); i++)
	  {         
	      if(e.craftMatrix.getStackInSlot(i) != null)
	      {
	       ItemStack j = e.craftMatrix.getStackInSlot(i);
	       if(j.getItem() != null && j.getItem() == LOZmod.magic_powder)
	       {
	        ItemStack k = new ItemStack(LOZmod.magic_powder, 2, (j.getItemDamage() + 1));
	        e.craftMatrix.setInventorySlotContents(i, k);
	       }
	      }  
	  }
}

}

 

Stuff in main class:

@EventHandler
public void PreInitialization(FMLPreInitializationEvent event) {
//blah blah blah
FMLCommonHandler.instance().bus().register(new LOZmodEVENT());
//blah blah blah
}

Legend of Zelda Mod[updated September 20th to 3.1.1]

Extra Achievements(Minecraft 1.8!)[updated April 3rd to 2.3.0]

Fancy Cheeses[updated May 8th to 0.5.0]

Link to comment
Share on other sites

Hi Diesievben07

 

I've tried to do this but i cant....

 

MainClass:

 

package dk.vikke.lefood;

 

import net.minecraft.creativetab.CreativeTabs;

import net.minecraft.init.Items;

import net.minecraft.item.Item;

import net.minecraft.item.Item.ToolMaterial;

import net.minecraft.item.ItemStack;

import net.minecraftforge.common.util.EnumHelper;

import cpw.mods.fml.common.FMLCommonHandler;

import cpw.mods.fml.common.Mod;

import cpw.mods.fml.common.Mod.EventHandler;

import cpw.mods.fml.common.event.FMLPreInitializationEvent;

import cpw.mods.fml.common.eventhandler.Event;

import cpw.mods.fml.common.registry.GameRegistry;

import dk.vikke.lefood.items.BSlice;

import dk.vikke.lefood.items.Knife;

 

@Mod(modid = MainClass.MODID, name = MainClass.NAME, version = MainClass.VERSION)

public class MainClass {

public static final String MODID = "lefood";

public static final String NAME = "Le Food";

public static final String VERSION = "1.0.0";

 

//Creative Tab

public static CreativeTabs leFoodTaB = new CreativeTabs("leFoodTab") {

@Override

public Item getTabIconItem() {

return BSlice;

}

};

 

//Food

public static Item BSlice = new BSlice(2, 0.3F, false).setUnlocalizedName("BSlice");

 

//Tools

public static ToolMaterial leFoodKnife = EnumHelper.addToolMaterial("leFoodKife", 0, 19, 1.0F, 1.0F, 0);

public static Item Knife = new Knife(leFoodKnife).setMaxStackSize(1).setUnlocalizedName("Knife");

 

public MainClass() {

//Registry

GameRegistry.registerItem(BSlice, "BSlice");

GameRegistry.registerItem(Knife, "Knife");

 

//Crafting

GameRegistry.addShapelessRecipe(new ItemStack(BSlice, 2), new ItemStack(Items.bread), new ItemStack(Knife.setContainerItem(Knife)));

GameRegistry.addShapedRecipe(new ItemStack(Knife, 1), new Object[]{ "X", "Z", 'X', Items.iron_ingot, 'Z', Items.stick});

}

}

 

 

Knife Class:

 

package dk.vikke.lefood.items;

 

import dk.vikke.lefood.MainClass;

import net.minecraft.item.Item;

import net.minecraft.item.ItemStack;

import net.minecraft.item.ItemSword;

 

public class Knife extends ItemSword {

 

public Knife(ToolMaterial id) {

super(id);

this.setCreativeTab(MainClass.leFoodTaB);

this.setTextureName(MainClass.MODID + ":" + "Knife");

 

@Override

this.getContainerItem();

this.hasContainerItem(true);

}

 

}

 

Link to comment
Share on other sites

package yourpackage;

public class item_damagable extends Item{

public String data ="mod"+ ":" + this.getClass().getName();

public item_damagable()

    {

        super();

        setMaxStackSize(1);

        setNoRepair();

        setMaxDamage(128);  //how often is it usable? now 128

        this.setUnlocalizedName(data);

        this.setTextureName(data);

        this.setCreativeTab(tab);

    }

 

@SideOnly(Side.CLIENT)

    public boolean hasEffect(ItemStack par1ItemStack)            // the item has a enchanting effect. delete it if you don't want it

    {

        return true;

    }

 

    @Override

    public boolean doesContainerItemLeaveCraftingGrid(ItemStack itemStack)

    {

        return false;

    }

 

    @Override

    public boolean getShareTag()

    {

        return true;

    }

 

    public boolean hasContainerItem(ItemStack itemStack)

    {

    return true;

    }

    @Override

    public ItemStack getContainerItem(ItemStack itemStack)

    {

        ItemStack stack = itemStack.copy();

 

        stack.setItemDamage(stack.getItemDamage() + 1);

        stack.stackSize = 1;

 

        return stack;

    }

   

Link to comment
Share on other sites

And in the crafting recipe like this:

GameRegistry.addShapelessRecipe(new ItemStack(Blocks.tallgrass, 1 , 0), new ItemStack(Blocks.tallgrass, 1 , 3), new ItemStack(ITEMNAMEOFTHEITEMTHATTAKESDAMAGE, 1, OreDictionary.WILDCARD_VALUE));

 

Hope that helps :)

 

Hi SantacreeperLP

 

Your code worked after i edited some stuff ;)

Im so thanks full :D

 

Heres my code now:

 

Knife Class

 

package dk.vikke.lefood.items;

 

import net.minecraft.item.Item;

import net.minecraft.item.ItemStack;

import cpw.mods.fml.relauncher.Side;

import cpw.mods.fml.relauncher.SideOnly;

import dk.vikke.lefood.MainClass;

 

 

public class Knife extends Item{

  public String data ="mod"+ ":" + this.getClass().getName();

  public Knife()

    {

        super();

        setMaxStackSize(1);

        setNoRepair();

        setMaxDamage(19);  //how often is it usable? now 128

        this.setUnlocalizedName("Knife");

        this.setTextureName(MainClass.MODID + ":" + "Knife");

        this.setCreativeTab(MainClass.leFoodTab);

    }

 

    @Override

    public boolean doesContainerItemLeaveCraftingGrid(ItemStack itemStack)

    {

        return false;

    }

 

    @Override

    public boolean getShareTag()

    {

        return true;

    }

 

    public boolean hasContainerItem(ItemStack itemStack)

    {

      return true;

    }

    @Override

    public ItemStack getContainerItem(ItemStack itemStack)

    {

        ItemStack stack = itemStack.copy();

 

        stack.setItemDamage(stack.getItemDamage() + 1);

        stack.stackSize = 1;

 

        return stack;

    }

}

 

 

And The Recipe:

 

GameRegistry.addShapelessRecipe(new ItemStack(BSlice, 2), new ItemStack(Items.bread), new ItemStack(Knife, 1, OreDictionary.WILDCARD_VALUE));

 

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.