Posted October 28, 201410 yr 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.
October 28, 201410 yr Author Never mind, I figured it out. Apparently, the method getItemInUse() made me crash while the method getHeldItem() didn't.
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.