BoonieQuafter-CrAfTeR Posted July 17, 2015 Share Posted July 17, 2015 so im making a item that allows flying, but if the item is not in the inventory I want it to disable flying, and Ive tried doing this multiple ways. problem is not matter what I haven't been able to do it. so here is my last attempt at it. if there are any problems with the code please let me know. any help is greatly appreciated. thanks. onUpdate method: public class DnaZeusInfused extends Item { public void onUpdate(ItemStack stack, World world, Entity entity, int par4, boolean par5) { super.onUpdate(stack, world, entity, par4, par5); { EntityPlayer player = (EntityPlayer) entity; boolean hasItem = player.inventory.hasItem(ModItems.DnaZeusInfused); if (player.inventory.hasItem(ModItems.DnaZeusInfused)) { player.capabilities.allowFlying = true; } else if (hasItem == false) { player.capabilities.allowFlying = false; } if (player.capabilities.isFlying) { player.addPotionEffect(new PotionEffect(Potion.damageBoost.id, 1, 1)); player.addPotionEffect(new PotionEffect(Potion.resistance.id, 1, 1)); } else { player.addPotionEffect(new PotionEffect(Potion.damageBoost.id, 0, 0)); player.addPotionEffect(new PotionEffect(Potion.resistance.id, 0, 0)); } } } Quote Im serious don't look at it!! Link to comment Share on other sites More sharing options...
coolAlias Posted July 17, 2015 Share Posted July 17, 2015 That's because the Item#onUpdate (and any other such methods, e.g. onArmorTick) are only called while the item is in your inventory. To change something when it is NOT there, you have to be able to check from somewhere else, such as the PlayerTickEvent. Quote http://i.imgur.com/NdrFdld.png[/img] Link to comment Share on other sites More sharing options...
BoonieQuafter-CrAfTeR Posted July 17, 2015 Author Share Posted July 17, 2015 I failed SORRY Quote Im serious don't look at it!! Link to comment Share on other sites More sharing options...
BoonieQuafter-CrAfTeR Posted July 17, 2015 Author Share Posted July 17, 2015 where can I find a example of a playertickevent current code: public void playerTick(PlayerTickEvent event) { boolean hasItem = event.player.inventory.hasItem(ModItems.DnaZeusInfused); if (event.player.inventory.hasItem(ModItems.DnaZeusInfused)) { event.player.capabilities.allowFlying = true; if (hasItem == false) { event.player.capabilities.allowFlying = false; } } } Quote Im serious don't look at it!! Link to comment Share on other sites More sharing options...
coolAlias Posted July 17, 2015 Share Posted July 17, 2015 Do you know how to use events? You need to put @SubscribeEvent annotation above your method and then register the containing class to the appropriate event bus - in this case, TickEvents are fired on the FML bus: FMLCommonHandler.instance().bus().register(new ClassContainingYourEvent()); Also, you check if the player has the same item twice. hasItem = checkInventory. if (checkInventory again, even though I just checked it...) You may want to consider using more curly braces to make your logic clearer as well. if (condition) do something // vs. if (condition) { do something } The second is much less prone to mistakes, especially as nesting gets deeper. Quote http://i.imgur.com/NdrFdld.png[/img] Link to comment Share on other sites More sharing options...
BoonieQuafter-CrAfTeR Posted July 17, 2015 Author Share Posted July 17, 2015 ok thanks it works now, well, not exactly the way I wanted it to, if your still flying it doesn't disable your ability to fly, but after you land it does. how should I fix this. Quote Im serious don't look at it!! Link to comment Share on other sites More sharing options...
Elix_x Posted July 17, 2015 Share Posted July 17, 2015 ok thanks it works now, well, not exactly the way I wanted it to, if your still flying it doesn't disable your ability to fly, but after you land it does. how should I fix this. capabilities.isFlying... Quote Check out my mods: BTAM Armor sets Avoid Exploding Creepers Tools compressor Anti Id Conflict Key bindings overhaul Colourfull blocks Invisi Zones Link to comment Share on other sites More sharing options...
BoonieQuafter-CrAfTeR Posted July 17, 2015 Author Share Posted July 17, 2015 and what do I do if other flying items don't work now because of the event? also will this cause compatibility errors with other mods? Edit: Should I add potion effects on the server side? Quote Im serious don't look at it!! Link to comment Share on other sites More sharing options...
coolAlias Posted July 18, 2015 Share Posted July 18, 2015 and what do I do if other flying items don't work now because of the event? also will this cause compatibility errors with other mods? Edit: Should I add potion effects on the server side? There is no way for you to know what other mods might be adding flying, but if you and they both code correctly, you should be okay. What I mean is, each mod should be applying player.capabilities.allowFlying=true every tick that it is allowed, and only turning it off ONCE, so if another mod still has a situation that allows flying, you turn it off, but they immediately turn it back on. It gets trickier with setting isFlying to false, because if you do that right away, even if the other mod allows flying again, the player will still fall out of the sky, so you should set isFlying to false on the NEXT tick IF the player is still not allowed to fly. Potions: Yes, apply them on the server. As a general rule, apply EVERYTHING on the server. Quote http://i.imgur.com/NdrFdld.png[/img] Link to comment Share on other sites More sharing options...
BoonieQuafter-CrAfTeR Posted July 19, 2015 Author Share Posted July 19, 2015 how do I get the next tick of the player may I ask? Quote Im serious don't look at it!! Link to comment Share on other sites More sharing options...
BoonieQuafter-CrAfTeR Posted July 20, 2015 Author Share Posted July 20, 2015 bump Quote Im serious don't look at it!! Link to comment Share on other sites More sharing options...
Elix_x Posted July 20, 2015 Share Posted July 20, 2015 how do I get the next tick of the player may I ask? Player tick events??? There's value for each entity of how long it has lived. Now just mpa that value and check in next tick... Quote Check out my mods: BTAM Armor sets Avoid Exploding Creepers Tools compressor Anti Id Conflict Key bindings overhaul Colourfull blocks Invisi Zones Link to comment Share on other sites More sharing options...
BoonieQuafter-CrAfTeR Posted July 20, 2015 Author Share Posted July 20, 2015 yeah but it wont just let me add 1 to the time existed. I need an example, please. Quote Im serious don't look at it!! Link to comment Share on other sites More sharing options...
Recommended Posts
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.