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

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!

  • Author

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

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
    }

  • Author

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

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 ;)

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.