Minecraft create your own weapon

This tutorial will involve coding a couple of scripts but its very easy and understandable.


By the way this is for version 1.1


Now you need to start of with your mod****file.

Next you need to define your item in that same mod****file.

For example:

Public static final ItemDagger = (new ItemDagger(100)).
any other features would go here.

So if the item was a dagger it would look like so:


package net.minecraft.src; 


public class ItemDagger extends Item 


    public ItemDagger(int i) 
    { 
         super(i);



Nothing confusing yet:


the reason (int i) is there is because later on we will make a simple function that will allow for the super(i) to work.


Next add your flashy epic features.



maxStackSize = 1; This is of course the maximum stack size 
maxDamage = 3124; Durability set to 3124.
field_22047_d = 20; Damage,health or 20 hearts.
}               Finishing braces.

see simple nothing confusing, anyway lets move on.

Now we need the item to take damage:


  public void hitEntity(ItemStack itemstack, EntityLiving entityliving) 
    { 
        itemstack.damageItem(1); 
    } 


    public void hitBlock(ItemStack itemstack, int i, int j, int k, int l) 
    { 
        itemstack.damageItem(2); 
    } 


These are just a couple of function that will allow the weapon to take damage.


By the way this script can be modified so feel free just to play around with the numbers until you understand their values.


Now the field "field_22047_d;" function we created earlier needs to be verified in order for it to work.



 public int getDamageVsEntity(Entity entity) 
    { 
        return field_22047_d; 
    } 


    public boolean isFull3D() 
    { 
        return true; 
    } 



Finally:


to finish off:




    private int field_22047_d; 




if it did not compile properly just follow this full code:



public class ItemDagger extends Item 



    public ItemDagger(int i) 
    { 
        super(i); 
        maxStackSize = 1; 
        maxDamage = 500; 
        field_22047_d = 5; 
    } 


    public void hitEntity(ItemStack itemstack, EntityLiving entityliving) 
    { 
        itemstack.damageItem(1); 
    } 


    public void hitBlock(ItemStack itemstack, int i, int j, int k, int l) 
    { 
        itemstack.damageItem(2); 
    } 


    public int getDamageVsEntity(Entity entity) 
    { 
        return field_22047_d; 
    } 


    public boolean isFull3D() 
    { 
        return true; 
    } 
        
    private int field_22047_d; 
}





This is exactly the same what we were trying to build its just fully completed.
 

Share this

Previous
Next Post »