Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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;

}

  • Author

Could you show me an example? Everything I try seems to crash my game. I tried it with out the statement and it doesn't crash so It's not something else.

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.

  • Author

That works, but how would I get it to set allowFlying to false if your hand is empty? That's what crashes

Hold on, while there is no item in the player's hand you want them to be able to fly? And when they are holding your item they can't fly? That makes no sense whatsoever.

Don't make mods if you don't know Java.

Check out my website: http://shadowfacts.net

Developer of many mods

  • Author

Umm, No... I just said "how would I get it to set allowFlying to false if your hand is empty?"

 

On right click it allows the user to fly, if you right click or choose another item, the flight is taken off.

Where's the confusion?

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.

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.

  • Author

Sorry, Was up too late to be attempting to code. I understand now. Thank you for your time and help! Much appreciated.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.