Jump to content

Checking Held Item


Adityagupta

Recommended Posts

I am trying to make a mod that lets you throw nether stars like ninja shurikens. For that, I am trying to check a player's held item, but whenever I do, my game crashes. My code is as follows:

 

package org.devoxx4kids.forge.mods;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.util.ChatComponentText;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;

public class NinjaSkills {

@SubscribeEvent
public void throwShuriken(PlayerInteractEvent event){
	if (event.action != Action.RIGHT_CLICK_AIR && event.action != Action.RIGHT_CLICK_BLOCK) {
		return;
	}

	if (event.entityPlayer.getItemInUse().getItem() != Items.nether_star) {
		return;
	}

	event.entityPlayer.addChatMessage(new ChatComponentText("You threw a shuriken!"));
}
}

 

I have tried checking a player's held item in MANY other mods, but it never works.

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.