Jump to content

Recommended Posts

Posted

there are a couple of ways but one is to set up an event handler and use something like this.

@SubscribeEvent
public void onLivingUpdateEvent(LivingUpdateEvent event) {
if (event.entity instanceof EntityPlayer) {
	EntityPlayer player = (EntityPlayer)event.entity;
	ItemStack heldItem = player.getHeldItem();
	if (heldItem != null && heldItem.isItemEqual(new ItemStack(Items.arrow))) {
		System.out.println("True");
	}
}
}

I am the author of Draconic Evolution

Posted

I am afraid it didn't work. The method in my main mod class is:

public void Load(FMLLoadEvent e)

{

FMLCommonHandler.instance().bus().register(new PlayerEventHandler());

}

 

and the PlayerEventHandler class is:

 

public class PlayerEventHandler {

@SubscribeEvent

public void onLivingUpdateEvent(LivingUpdateEvent event) {

if (event.entity instanceof EntityPlayer) {

EntityPlayer player = (EntityPlayer)event.entity;

ItemStack heldItem = player.getHeldItem();

if (heldItem != null && heldItem.isItemEqual(new ItemStack(Items.arrow))) {

player.addExperience(1999);

}

}

}

}

 

Posted

Don't get so mad. I replied to the other guy. It seems it just ignores what I coded. About your advice, I get an error when I replace LivingUpdateEvent with PlayerTickEvent

Posted

I fixed that problem with PlayerTickEvent, but it still does nothing. Here is the code, if you can help me, you're the best:

 

public void Load(FMLLoadEvent e)

{

MinecraftForge.EVENT_BUS.register(new PlayerEventHandler());

}

 

 

public class PlayerEventHandler {

@SubscribeEvent

public void onPlayerTickEvent(PlayerTickEvent event) {

if (event.player instanceof EntityPlayer) {

EntityPlayer player = (EntityPlayer)event.player;

ItemStack heldItem = player.getHeldItem();

if (heldItem != null && heldItem.isItemEqual(new ItemStack(Items.arrow))) {

System.out.println("True");

}

}

}

}

 

Posted

public void Load(FMLLoadEvent e)

{

MinecraftForge.EVENT_BUS.register(new PlayerEventHandler());

}

Why not FMLPreInitializationEvent ?

 

Also you could check InventoryPlayer for other methods to check item in slots and such.

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.