Jump to content

[1.7.10] attackEntityFrom not working


Recommended Posts



I need to make delay before attack, this is my code:


    private int attackDelay;
    private int attackTimer;
    private Entity attackedEntity = null;
    public ItemGreatsword(Item.ToolMaterial par1ToolMaterial, int par2AttackDelay)
        this.field_150933_b = par1ToolMaterial;
        this.maxStackSize = 1;
        this.field_150934_a = 4.0F + par1ToolMaterial.getDamageVsEntity();
    	//this.attackDelay = par2AttackDelay;
        this.attackDelay = 40;
    public boolean onLeftClickEntity(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, Entity par3Entity)
    	if (attackedEntity == null)
    	    this.attackTimer = (this.attackDelay + 1);
    	    this.attackedEntity = par3Entity;
        return true;
    public void onUpdate(ItemStack par1ItemStack, World par2World, Entity par3Entity, int par4, boolean par5)
        super.onUpdate(par1ItemStack, par2World, par3Entity, par4, par5);
        EntityPlayer player = (EntityPlayer)par3Entity;
ItemStack equippedItem = player.getCurrentEquippedItem();

if (this.attackTimer > 0)
    System.out.println("AttackTimer: " + this.attackTimer);

if (this.attackTimer == 1)
	if (!par2World.isRemote)
	    this.attackedEntity.attackEntityFrom(DamageSource.lava, 6.0F);
	    this.attackedEntity = null;
	    this.attackTimer = 0;

if (equippedItem == par1ItemStack) 
	player.addPotionEffect(new PotionEffect(Potion.digSlowdown.getId(), 0, 3));


Part of code (System.out.println("Test")) working, entity != null too, i checked it, but entity wont die.



Link to comment
Share on other sites

Every field in an


class will be shared across all instanced of that


. You have to store those values in the


's NBT.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.


1.12 -> 1.13 primer by williewillus.


1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.



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.

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.


  • Create New...

Important Information

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