Jump to content

Testing Held Item


J-Nutz

Recommended Posts

I currently have an item that on right click grants the player creative flight. When either right clicked again, or the player selects another item/empty hand the flight gets taken away. How would I do that? My current code doesn't do so.

 

ItemStack heldItem = player.getCurrentEquippedItem();

if(heldItem.getItem() != ToolInits.flightWand)
{

	allowFlight = false;

}

Link to comment
Share on other sites

ItemStack heldItem = player.getCurrentEquippedItem();
if (heldItem != null)
{
if (heldItem.getItem() != ToolInits.flightWand)
{
	allowFlight = false;
}
}

 

Those are literally basics. If that is not the case, please post full code and/or what you are trying to do.

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

Some time ago there was similar problem posted. Someone wanted to execute some code (turn off buff) JUST AFTER you swapped item in hand (stopped holding it).

 

Problem here is that there is NO method called there.

BUT, there is a way of doing it.

 

This might be outdated, but I doubt there is other way for now:

1. Add IExtendedEntityProperties to EntityPlayer (may be even server-side only since Inventory is there)

2. Add a boolean flightItemBeingUsed = false;

3. Since you are activating flight by right-clicking (item use) you will use this:

ExtendedPlayer.get(player).flightItemBeingUsed = true;

4. Now: Subscribe to PlayerTickEvent and write:

if (ExtendedPlayer.get(player).flightItemBeingUsed)
{
ItemStack heldItem = player.getCurrentEquippedItem();
if (heldItem != null && heldItem.getItem() == ToolInits.flightWand)
	allowFlight = true;
else
{
	allowFlight = false;
	ExtendedPlayer.get(player).flightItemBeingUsed = false;
}
}

 

I belive this should work. Also - you could obviously do it MUCH simplier without using IEEP, BUT then your mod will be incomatybile with other fight-allowing commands/mods/items.

 

Edit: made simple change in code. Also - this is almost pseudo-code (written it without IDE), you SHOULD be able to optimize it a bit. (I think)

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

You have no idea how to use IEEP, do you?

Anyway - this is the moment that you decide to either spend week learning new (very useful) feature that will come in handy later, or you say "nope" and start coding incompatybile stuff or simply not coding what you want.

 

Tutorial on how to start on IEEP: (2nd post)

http://www.minecraftforum.net/forums/mapping-and-modding/mapping-and-modding-tutorials/1571567-forge-1-6-4-1-8-eventhandler-and

Funny how i link this tutorial this many times :)

 

You should make new class for IEEP interface,  .get(EntityPlayer) is my wrapper for getting IEEP of given PlayerEntity (see tutorial).

 

1.7.10 is no longer supported by forge, you are on your own.

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.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.