Jump to content

Recommended Posts

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.

Posted

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

  }

}

 

Posted

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.

Posted

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

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