We have succesfully created and registered our CraftingHandler, but we will have to code some more to receive all information that it puts out.
First thing we do is to create the CraftingHandler class.
this is pretty basic stuff:
public class ModCraftingHandler implements ICraftingHandler{
}
Now, you will get an error, by saying this, but thats because we need to 'add unimplemented methods',
so to do that you hover your mouse over the error of your mod class and click 'add unimplemented methods'.
It should now look something like this:
public class ModCraftingHandler implements ICraftingHandler{
@Override
public void onCrafting(EntityPlayer player, ItemStack item, IInventory craftMatrix) {
// TODO Auto-generated method stub
}
@Override
public void onSmelting(EntityPlayer player, ItemStack item) {
// TODO Auto-generated method stub
}
}
After this step is done, its all up to you.
The most common thing to do is to add this bit of code to your onCrafting() or onSmelting():
if(item.itemID == Item.beefCooked.itemID){
System.out.println("Hope it tastes!");
}
This bit of code says:
If the item/block created after crafting/smelting has the same id as the Item of cooked beef. I want to print to the console: "Hope it tastes!"
You switch out the println() with something of your choice, for example change a boolean or something in your main mod class.
it says item but can mean anything! (Block or Item), this is a itemstack, not a item!
Everything should look something like this:
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import cpw.mods.fml.common.ICraftingHandler;
public class ModCraftingHandler implements ICraftingHandler{
public void onCrafting(EntityPlayer player, ItemStack item, IInventory craftMatrix) {
}
public void onSmelting(EntityPlayer player, ItemStack item) {
if(item.itemID == Item.beefCooked.itemID){
System.out.println("Hope it tastes!");
}
}
}
Hope this helped you!
Be sure to subscribe and follow Link Removed!
Everything I have done is at my youtube channel!
Have any ideas? Please feel free to comment at any of my videos or in Link Removed! You can also email me at: [email protected]
All mods i am creating is working for 1.4.7! and contains video tutorial!
Uploading Modding Tutorials every single day!
Hit up my channel at http://youtube.com/ScratchForFun!
Today we create a 'CraftingHandler' for 1.4.7!
Main mod class
Well, a craftingHandler is a handler that receives information every time you smelt or craft an item, or smelt something.
So, first thing we will need to do is to add some code to our main mod class.
And, as you probaly guessed, we will need to create our CraftingHandler.
To do so you write:
So, yes we have now created our CraftingHandler, but now we need to register it.
To do so you just need this bit of code:
CraftingHandler class
First thing we do is to create the CraftingHandler class.
this is pretty basic stuff:
Now, you will get an error, by saying this, but thats because we need to 'add unimplemented methods',
so to do that you hover your mouse over the error of your mod class and click 'add unimplemented methods'.
It should now look something like this:
After this step is done, its all up to you.
The most common thing to do is to add this bit of code to your onCrafting() or onSmelting():
This bit of code says:
If the item/block created after crafting/smelting has the same id as the Item of cooked beef. I want to print to the console: "Hope it tastes!"
You switch out the println() with something of your choice, for example change a boolean or something in your main mod class.
it says item but can mean anything! (Block or Item), this is a itemstack, not a item!
Everything should look something like this:
Hope this helped you!
Be sure to subscribe and follow Link Removed!
Everything I have done is at my youtube channel!
Have any ideas? Please feel free to comment at any of my videos or in Link Removed! You can also email me at: [email protected]