Jump to content

Item not being damaged, think it is the entity variable required


Jakemichie97

Recommended Posts

So I am developing a mod which requires an item with cooldown, I need to have the item be damaged by 99 when used (right clicked) but the onItemRightCick entityplayer variable I think is not letting the item be damaged.

 

Code:

 

 

package jcm2606.sorcerycraft.common.items;

import jcm2606.sorcerycraft.common.core.reference.SCItemShine;
import net.minecraft.src.Entity;
import net.minecraft.src.EntityLiving;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.ItemStack;
import net.minecraft.src.World;

public class ItemWandFire extends SCItemShine{

public ItemWandFire(int par1) {
	super(par1);
	this.setMaxDamage(100);
}

/**
     * Called each tick as long the item is on a player inventory. Uses by maps to check if is on a player hand and
     * update it's contents.
     */
    public void onUpdate(ItemStack par1ItemStack, World par2World, Entity par3Entity, int par4, boolean par5) {
    	if(par1ItemStack.getItemDamage() > 0)
    	{
    		//par1ItemStack.damageItem(-1, (EntityLiving) par3Entity); Again commented this line out for testing
    	}
    }
    
    /**
     * Callback for item usage. If the item does something special on right clicking, he will have one of those. Return
     * True if something happen and false if it don't. This is for ITEMS, not BLOCKS
     */
    @Override
public boolean onItemUse(ItemStack itemStack, EntityPlayer entityPlayer, World world, int x, int y, int z, int l, float f1, float f2, float f3) {
	itemStack.damageItem(1, entityPlayer);
	System.out.println(this.isDamageable());  //Testing
	return true;
    }
}

 

 

Link to comment
Share on other sites

I think you're possibly looking for this -

    public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) {
        if (!par3EntityPlayer.capabilities.isCreativeMode) {
                par1ItemStack.damageItem(99, par3EntityPlayer);
        }

On every right click it'll damage the item by '99'.

 

Another example, if you want it to shoot a snowball -

    public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) {
        if (!par3EntityPlayer.capabilities.isCreativeMode) {
                par1ItemStack.damageItem(99, par3EntityPlayer);
        }

        par2World.playSoundAtEntity(par3EntityPlayer, "random.bow", 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));

        if (!par2World.isRemote) {
        	par2World.spawnEntityInWorld(new EntitySnowball(par2World, par3EntityPlayer));
        }

        return par1ItemStack;
    }

 

Just a note, I've got the code for making it not 'work' if the damage isn't 0, if you want it ask, unless you want the fun of working it out yourself ;)

Link to comment
Share on other sites

Might the problem be in onItemUse? 

    @Override
public boolean onItemUse(ItemStack itemStack, EntityPlayer entityPlayer, World world, int x, int y, int z, int l, float f1, float f2, float f3) {
	itemStack.damageItem(1, entityPlayer);
	System.out.println(this.isDamageable());  //Testing
	[b]return true;[/b]
    }

 

I've noticed that when that method returns true clientside, it is never called serverside.  Try adding an if (world.isRemote){return false;} statement near the beginning of the method body.

Link to comment
Share on other sites

If you're talking about -

if (!par3EntityPlayer.capabilities.isCreativeMode) {

And I understand you correctly, that just means if you're not in creative mode then run this, basically how it doesn't damage the item when you're in creative mode. (Apologies if I misunderstood.)

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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