Posted April 21, 201411 yr 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.
April 21, 201411 yr 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 } }
April 21, 201411 yr 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 ); I typically use LivingUpdateEvent since I have various extended properties to update anyway. http://i.imgur.com/NdrFdld.png[/img]
April 21, 201411 yr Author but then if you have another method of flying, it will disable that. At least I think so.
April 21, 201411 yr 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. http://i.imgur.com/NdrFdld.png[/img]
April 21, 201411 yr The way that i've done it for DivineRPG is using a tick handler, well in 1.7 you have to make your own, but it still works great! Former developer for DivineRPG, Pixelmon and now the maker of Essence of the Gods
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.