Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hi!

 

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.setMaxDamage(par1ToolMaterial.getMaxUses());
        this.setCreativeTab(CreativeTabs.tabCombat);
        this.field_150934_a = 4.0F + par1ToolMaterial.getDamageVsEntity();
    	//this.attackDelay = par2AttackDelay;
        this.attackDelay = 40;
    }
    
    @Override
    public boolean onLeftClickEntity(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, Entity par3Entity)
    {
    	if (attackedEntity == null)
    	{
    	    this.attackTimer = (this.attackDelay + 1);
    	    this.attackedEntity = par3Entity;
    	}
    	
        return true;
    }
    
    @Override
    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)
{
    --this.attackTimer;
    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;
	    System.out.println("Test");
	}
}

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.

 

Thanks.

Every field in an

Item

class will be shared across all instanced of that

Item

. You have to store those values in the

ItemStack

'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.

 

http://www.howoldisminecraft1710.today/

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.