RedBullSlurpie Posted May 10, 2016 Posted May 10, 2016 So i have my mod created, but someone has found an issue. Basically when using my mod with any other mod that allows flight via armor, or ring, or any way, my mod disables flight for ANY other mod out there. For example, my mod adds some armor, more specifically Topaz Armor that can fly with double tapping space bar. Say, I use the ArmorPlus mod with mine which has armor called The Ultimate Armor for example, if I double tap with that armor, I can fly. however if i use my mod with armorplus mod together, my mod still flys with my armor, but disables all flight for ArmorPlus mod, or for that matter any other mod. How can I fix this? I was told to do this but am confused. "he explained that you don't need to (and shouldn't) change the flag every player tick. Just check when armor is equipped and then change the flag then and only then". Here is my Event Handler for Flight for Topaz Armor. http://pastebin.com/eARwJ8A6 Any help is greatly appreciated, thank you. Quote
p455w0rd Posted May 10, 2016 Posted May 10, 2016 I could be wrong, but I think it would be better to do this on something like an armor item's onUpdate event..by using the PlayerTick event, you're messing with anything any other mod might be using that event for..when you set the value of player.capabilities.allowFlying to false, you're doing this on a global scale.. Also..whoever told you that this doesn't need to happen every tick is correct..doing a check every tick should be fine (I would assume)... If it has changed from it's previous state, then update player accordingly Quote http://p455w0rd.net/images/forumsignature.png[/img]
RedBullSlurpie Posted May 10, 2016 Author Posted May 10, 2016 I'm still confused as to what to change in my code? Could you help me any farther? Quote
p455w0rd Posted May 10, 2016 Posted May 10, 2016 Okay, for your Item (assuming it extends Item (net.minecraft.item.Item), you can override the onUpdate method which takes the following parameters: ItemStack, World, Entity, int, boolean from Entity you can check that it is an instance of EntityPlayer. if it is an instance of EntityPlayer, you can get the player's inventory to check if they have the required pieces of armor equipped if they have all of the required pieces, you can check for capabilities.isFlying and so on... Quote http://p455w0rd.net/images/forumsignature.png[/img]
coolAlias Posted May 10, 2016 Posted May 10, 2016 You DO need to use the PlayerTickEvent because Armor doesn't tick when it's not worn*, so the only way to remove the flying effect when no longer wearing your armor is via a tick event. The trick to mod compatibility is to set allowFlying to true every tick that it should be true, but only set it to false ONCE when the condition is no longer met. To do that, you need a separate boolean 'wasFlyingAllowed'. This way, you only toggle flying off once, and any other mod that says flying is still allowed sets it during their tick event. Note that it's still not perfect - if your tick event is last to evaluate, there will be one tick in which the player cannot fly and will begin to fall (if you also set #isFlying to false), even though the very next tick they will be allowed to fly again. It's a wonder there isn't yet a universal way to ensure inter-mod flying compatibility (at least that I've heard of), given how many mods add it. * Yes, it still has #onUpdate called while in the player's inventory, but that won't happen if the armor is destroyed, moved to another inventory directly, etc. #onUpdate is not a reliable method of toggling off an ability. Quote http://i.imgur.com/NdrFdld.png[/img]
p455w0rd Posted May 10, 2016 Posted May 10, 2016 I was under the impression everything that is in InventoryPlayer is ticked..good to know =D Quote http://p455w0rd.net/images/forumsignature.png[/img]
coolAlias Posted May 10, 2016 Posted May 10, 2016 On 5/10/2016 at 2:39 AM, p455w0rd said: I was under the impression everything that is in InventoryPlayer is ticked..good to know =D You are not wrong; where you err is in assuming that armor is always going to remain in InventoryPlayer. I edited in some examples - armor breaks, is tossed or otherwise moved out of inventory directly from the equipment slot, or a mod simply sets it the slot to null or a different item. In all of those cases, the armor will not get a chance to have an update tick after being unequipped, and you'll be unable to toggle off whatever ability you had toggled on. If, however, you were using AttributeModifiers rather than relying on update ticks, then it would be fine. Too bad there isn't an 'allow flying' attribute modifier... hmm... 'flySpeed' as a new SharedMonsterAttribute, anyone? Quote http://i.imgur.com/NdrFdld.png[/img]
RedBullSlurpie Posted May 10, 2016 Author Posted May 10, 2016 Sadly I still can't figure this out. Could anyone give me the code needed to solve this issue? I've been at it for hours and can't figure it out. I'm not super smart when it comes to coding, I only know the basics. Quote
coolAlias Posted May 10, 2016 Posted May 10, 2016 All you need to do is add 'public boolean wasFlyingAllowed = false' to your event handler, set it to true when your armor is all on, and then only disable flying if it's true and not all of your armor is allowed: // Note: you should check for NULL on all of these or you WILL crash if (boots.getItem() == SlurpiesDonglesItems.topaz_boots && chestplate.getItem() == SlurpiesDonglesItems.topaz_chestplate && leggings.getItem() == SlurpiesDonglesItems.topaz_leggings && helmet.getItem() == SlurpiesDonglesItems.topaz_helmet) { event.player.capabilities.allowFlying = true; event.player.fallDistance = 0.0F; wasFlyingAllowed = true; } elseif (wasFlyingAllowed) { wasFlyingAllowed = false; // now you won't be constantly setting allowFlying to false if (!event.player.capabilities.isCreativeMode) { event.player.capabilities.isFlying = false; event.player.capabilities.allowFlying = false; } } Quote http://i.imgur.com/NdrFdld.png[/img]
RedBullSlurpie Posted May 10, 2016 Author Posted May 10, 2016 Okay I did what you said, but now im stuck flying in survival mode, like not stuck, but i can double tap spacebar without anything on and i'll fly. Quote
RedBullSlurpie Posted May 10, 2016 Author Posted May 10, 2016 Still can not get this. I've added in the code that you said, one of the lines, is not being read so it's grayed out. I'm not sure if that's the issue or not, but still having no luck. Quote
RedBullSlurpie Posted May 10, 2016 Author Posted May 10, 2016 This is my new code. I'll point out the line that isin't in use, which im not sure is causing the issue or not, but here is my new code, could anyone help me with what im doing wrong? Thanks. http://pastebin.com/av9JBSs7 Quote
coolAlias Posted May 10, 2016 Posted May 10, 2016 You didn't use the code as I wrote it, and you are using local variables instead of class fields. - wasFlyingAllowed needs to be a class field so that it is remembered from tick to tick rather than being recalculated every tick. - You don't need allowFlying at all - remove it. - You moved your code to disable flying inside of your check for if (allowFlying), meaning that as soon as you are not allowed to fly, it is impossible for your code to disable it... - Please take time to study basic Java and logic: if (wasFlyingAllowed) { } else if (wasFlyingAllowed) { // this is the same condition you just checked - how can it possibly ever run? // dead code } Quote http://i.imgur.com/NdrFdld.png[/img]
jeffryfisher Posted May 10, 2016 Posted May 10, 2016 If your need is general programming ability rather than specific Forge-wrapper tips, then you should seek out a personal friend or family member who can tutor you in programming/Java. You should never ever ask someone here to write your code for you (remember this forum's description: "This is not Java school"). Quote The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.
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.