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

Hi everybody, I'm making a piece of armor that allows flight, but when someone wares it, and the takes it off, they can still fly.  I am allowing flight by player.cappabilities.allowFlying = true, since I don't know any other way.  I can disallow flight is there is a method that gets called when someone takes the armor off, but I don't know of any such method.  Thanks in advance.

Pseudo-code, put it inside your armor class:

 

@Override

public void onArmorTick(World world, EntityPlayer player, ItemStack itemStack){

    if (// check if armor is there){

 

// allow flight here

  } else {

 

        // disable flight

  }

}

 

There's a reason that the else statement is there...

What he means is that the else statement cannot be called if you are not wearing the armor, because the armor is no longer ticking.

 

@OP The only way I know of to do this is to check in one of the player on update methods if they can fly and are no longer wearing the correct armor, then set allow flying and is flying to false (if not in creative :P); I typically use LivingUpdateEvent since I have various extended properties to update anyway.

but then if you have another method of flying, it will disable that.  At least I think so.

Yes, that's true, unless you also check for that other method. It gets tricky when a bunch of mods all add flying stuff, and then disable it, which is why you should enable flying every tick while your conditions are true, and only set it to false once if you can.

 

An example would be to set a flag in your extended properties that says "something is letting me fly" each tick while you are flying, then check that flag is true and your flying conditions are false to disable flying, and set that flag to false. This way, you only disable your particular flying that one time, so if another mod is adding flying each tick, you are not constantly disabling their flying, too.

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.