Jump to content

EnumAction won't work


GravityWolf

Recommended Posts

Hello! I know this is a very noob question, but getEnumAction() doesn't work...it doesn't do the action I set it to do. Here is my code:

 

package MysticRealms.Items;

import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.EnumAction;
import net.minecraft.item.EnumToolMaterial;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.world.World;
import MysticRealms.MysticRealms;

public class ItemWeapon extends Item {

int swingSpeed;

public ItemWeapon(int id, EnumToolMaterial material, int speed, String name /*String ability*/) {

	super(id);
	this.setCreativeTab(MysticRealms.mysticTab);
	this.setUnlocalizedName(name);
	swingSpeed = speed;

}

public void onUpdate(ItemStack stack, World world, Entity entity, int par4, boolean par5) {

	if(entity instanceof EntityPlayer) {

		EntityPlayer player = (EntityPlayer) entity;
            ItemStack equipped = player.getCurrentEquippedItem();
            
            if(equipped == stack) {
            	
            	if(swingSpeed == 0) {
            	
            		
            		
            	} else if (swingSpeed == 1) {
            		
                	player.addPotionEffect(new PotionEffect(Potion.digSpeed.id, 1, 0));
            		
            	} else if (swingSpeed == 2) {
            		
                	player.addPotionEffect(new PotionEffect(Potion.digSpeed.id, 1, 1));
            		
            	} else if (swingSpeed == 3) {
            		
            		player.addPotionEffect(new PotionEffect(Potion.digSpeed.id, 1, 2));
            		
            	} else if (swingSpeed == -1) {
            		
                	player.addPotionEffect(new PotionEffect(Potion.digSlowdown.id, 1, 0));
            		
            	} else if (swingSpeed == -2) {
            		
                	player.addPotionEffect(new PotionEffect(Potion.digSlowdown.id, 1, 1));
            		
            	} else if (swingSpeed == -3) {
            		
                	player.addPotionEffect(new PotionEffect(Potion.digSlowdown.id, 1, 2));
                	
            	} else if (swingSpeed == -4) {
            		
            		player.addPotionEffect(new PotionEffect(Potion.digSlowdown.id, 1, 3));
            		
            	}
                     	
            }

	}

}

public EnumAction getItemUseAction(ItemStack par1ItemStack)
    {
        return EnumAction.block;
    }

}

 

Thanks!

Link to comment
Share on other sites

I can't figure this out...here's my code:

 

public EnumAction getItemUseAction(ItemStack par1ItemStack)
    {
        return EnumAction.block;
    }

public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
    {
        par3EntityPlayer.setItemInUse(par1ItemStack, this.getMaxItemUseDuration(par1ItemStack));
        return par1ItemStack;
    }

 

It does nothing on right click...

Link to comment
Share on other sites

You also have to set a max use duration for your item, or it cannot be used. If you don't override this method, the default value from Item is 0.

@Override
    public int getMaxItemUseDuration(ItemStack par1ItemStack)
    {
        return 72000; // however long your item can be used, in ticks
    }

Link to comment
Share on other sites

You also have to set a max use duration for your item, or it cannot be used. If you don't override this method, the default value from Item is 0.

@Override
    public int getMaxItemUseDuration(ItemStack par1ItemStack)
    {
        return 72000; // however long your item can be used, in ticks
    }

 

It worked! Thanks! And I didn't know you moved here from MCForums :P

Link to comment
Share on other sites

You also have to set a max use duration for your item, or it cannot be used. If you don't override this method, the default value from Item is 0.

@Override
    public int getMaxItemUseDuration(ItemStack par1ItemStack)
    {
        return 72000; // however long your item can be used, in ticks
    }

 

It worked! Thanks! And I didn't know you moved here from MCForums :P

Great! Yeah, I just signed up with some problems of my own ;)

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.

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

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

Announcements



×
×
  • Create New...

Important Information

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