Jump to content

Forge Inventory Problem


NeverMind

Recommended Posts

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

Link to comment
Share on other sites

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

}

}

}

}

 

Link to comment
Share on other sites

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

}

}

}

}

 

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.