Jump to content

Need some help with code


RedBullSlurpie

Recommended Posts

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.

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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? :P

Link to comment
Share on other sites

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;
    }
}

Link to comment
Share on other sites

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
}

Link to comment
Share on other sites

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

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.

Link to comment
Share on other sites

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I was just trying to play my modded world when i randomly got this crash for no reason. I sorted through like every mod and eventually I realized it was LLibrary but I can't seem to find a solution to fix the crashing. I can't lose the world that I have that uses this mod please help me. Here's the report: https://pastebin.com/0D00B79i If anyone has a solution please let me know.  
    • 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑   Daftar Slot Ligawin88 adalah bocoran slot rekomendasi gacor dari Ligawin88 yang bisa anda temukan di SLOT Ligawin88. Situs SLOT Ligawin88 hari ini yang kami bagikan di sini adalah yang terbaik dan bersiaplah untuk mengalami sensasi tak terlupakan dalam permainan slot online. Temukan game SLOT Ligawin88 terbaik dengan 100 pilihan provider ternama yang dipercaya akan memberikan kepuasan dan kemenangan hari ini untuk meraih x500. RTP SLOT Ligawin88 merupakan SLOT Ligawin88 hari ini yang telah menjadi pilihan utama bagi pemain judi online di seluruh Indonesia. Setiap harinya jutaan pemain memasuki dunia maya untuk memperoleh hiburan seru dan kemenangan besar dalam bermain slot dengan adanya bocoran RTP SLOT Ligawin88. Tidak ada yang lebih menyenangkan daripada mengungguli mesin slot dan meraih jackpot x500 yang menggiurkan di situs SLOT Ligawin88 hari ini yang telah disediakan SLOT Ligawin88. Menangkan jackpot besar x500 rajanya maxwin dari segala slot dan raih kemenangan spektakuler di situs Ligawin88 terbaik 2024 adalah tempat yang menyediakan mesin slot dengan peluang kemenangan lebih tinggi daripada situs slot lainnya. Bagi anda yang mencari pengalaman judi slot paling seru dan mendebarkan, situs bo SLOT Ligawin88 terbaik 2024 adalah pilihan yang tepat. Jelajahi dunia slot online melalui situs SLOT Ligawin88 di link SLOT Ligawin88.
    • 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑   Daftar Slot Asusslot adalah bocoran slot rekomendasi gacor dari Asusslot yang bisa anda temukan di SLOT Asusslot. Situs SLOT Asusslot hari ini yang kami bagikan di sini adalah yang terbaik dan bersiaplah untuk mengalami sensasi tak terlupakan dalam permainan slot online. Temukan game SLOT Asusslot terbaik dengan 100 pilihan provider ternama yang dipercaya akan memberikan kepuasan dan kemenangan hari ini untuk meraih x500. RTP SLOT Asusslot merupakan SLOT Asusslot hari ini yang telah menjadi pilihan utama bagi pemain judi online di seluruh Indonesia. Setiap harinya jutaan pemain memasuki dunia maya untuk memperoleh hiburan seru dan kemenangan besar dalam bermain slot dengan adanya bocoran RTP SLOT Asusslot. Tidak ada yang lebih menyenangkan daripada mengungguli mesin slot dan meraih jackpot x500 yang menggiurkan di situs SLOT Asusslot hari ini yang telah disediakan SLOT Asusslot. Menangkan jackpot besar x500 rajanya maxwin dari segala slot dan raih kemenangan spektakuler di situs Asusslot terbaik 2024 adalah tempat yang menyediakan mesin slot dengan peluang kemenangan lebih tinggi daripada situs slot lainnya. Bagi anda yang mencari pengalaman judi slot paling seru dan mendebarkan, situs bo SLOT Asusslot terbaik 2024 adalah pilihan yang tepat. Jelajahi dunia slot online melalui situs SLOT Asusslot di link SLOT Asusslot.
    • 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑 Daftar Slot Galeri555 adalah bocoran slot rekomendasi gacor dari Galeri555 yang bisa anda temukan di SLOT Galeri555. Situs SLOT Galeri555 hari ini yang kami bagikan di sini adalah yang terbaik dan bersiaplah untuk mengalami sensasi tak terlupakan dalam permainan slot online. Temukan game SLOT Galeri555 terbaik dengan 100 pilihan provider ternama yang dipercaya akan memberikan kepuasan dan kemenangan hari ini untuk meraih x500. RTP SLOT Galeri555 merupakan SLOT Galeri555 hari ini yang telah menjadi pilihan utama bagi pemain judi online di seluruh Indonesia. Setiap harinya jutaan pemain memasuki dunia maya untuk memperoleh hiburan seru dan kemenangan besar dalam bermain slot dengan adanya bocoran RTP SLOT Galeri555. Tidak ada yang lebih menyenangkan daripada mengungguli mesin slot dan meraih jackpot x500 yang menggiurkan di situs SLOT Galeri555 hari ini yang telah disediakan SLOT Galeri555. Menangkan jackpot besar x500 rajanya maxwin dari segala slot dan raih kemenangan spektakuler di situs Galeri555 terbaik 2024 adalah tempat yang menyediakan mesin slot dengan peluang kemenangan lebih tinggi daripada situs slot lainnya. Bagi anda yang mencari pengalaman judi slot paling seru dan mendebarkan, situs bo SLOT Galeri555 terbaik 2024 adalah pilihan yang tepat. Jelajahi dunia slot online melalui situs SLOT Galeri555 di link SLOT Galeri555.
    • 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑 Daftar Slot Kocok303 adalah bocoran slot rekomendasi gacor dari Kocok303 yang bisa anda temukan di SLOT Kocok303. Situs SLOT Kocok303 hari ini yang kami bagikan di sini adalah yang terbaik dan bersiaplah untuk mengalami sensasi tak terlupakan dalam permainan slot online. Temukan game SLOT Kocok303 terbaik dengan 100 pilihan provider ternama yang dipercaya akan memberikan kepuasan dan kemenangan hari ini untuk meraih x500. RTP SLOT Kocok303 merupakan SLOT Kocok303 hari ini yang telah menjadi pilihan utama bagi pemain judi online di seluruh Indonesia. Setiap harinya jutaan pemain memasuki dunia maya untuk memperoleh hiburan seru dan kemenangan besar dalam bermain slot dengan adanya bocoran RTP SLOT Kocok303. Tidak ada yang lebih menyenangkan daripada mengungguli mesin slot dan meraih jackpot x500 yang menggiurkan di situs SLOT Kocok303 hari ini yang telah disediakan SLOT Kocok303. Menangkan jackpot besar x500 rajanya maxwin dari segala slot dan raih kemenangan spektakuler di situs Kocok303 terbaik 2024 adalah tempat yang menyediakan mesin slot dengan peluang kemenangan lebih tinggi daripada situs slot lainnya. Bagi anda yang mencari pengalaman judi slot paling seru dan mendebarkan, situs bo SLOT Kocok303 terbaik 2024 adalah pilihan yang tepat. Jelajahi dunia slot online melalui situs SLOT Kocok303 di link SLOT Kocok303.
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.