Jump to content

Recommended Posts

Posted

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.

 

Posted

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

Posted

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

Posted

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.

Posted

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

Posted

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.

Posted

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

Posted

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
}

Posted

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.

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 need to know what mod is doing this crash, i mean the mod xenon is doing the crash but i want to know who mod is incompatible with xenon, but please i need to know a solution if i need to replace xenon, i cant use optifine anymore and all the other mods i tried(sodium, lithium, vulkan, etc) doesn't work, it crash the game.
    • I have been trying to solve a consistent crashing issue on my brother's computer where it will crash during the "Scanning Mod Candidates" phase of the loading process that starts when you click the play button on the Minecraft launcher. The issue seems to stem from a missing library that it mentions in the log file I provide below. I might I'm missing the bigger issue here for a smaller one but hopefully someone can find what I'm missing. Here's all of the stuff that I've been able to figure out so far: 1. It has nothing to do with mods, the crash happened with a real modpack, and even when I made a custom modpack and launched it without putting ANY mods into it (That is where the log file comes from by the way). 2. I have tried to find this class like a file in the Minecraft folders, but I've had no luck finding it (I don't think it works like that, but since I really don't understand how it works, I just figured I'd try). 3. I haven't seen anyone else have this issue before. 4. I know that my modpack (with mods) does work since I've run it on my computer, and it works fantastic. For some reason my brother's computer can't seem to run anything through curseforge. 5. This is for Minecraft version 1.20.1, Minecraft launcher version 3.4.50-2.1.3, forge 47.3.0, and curseforge app version 1.256.0.21056 6. My brother is using a Dell laptop from 6 years ago running Windows 10 (If you think more info on this would help, please ask as I do have it. I'm just choosing not to put it here for now). 7. I have reinstalled the curseforge app and installed Minecraft version 1.20.1. I have not reinstalled Minecraft or forge 47.3.0 but I didn't know if that would help. 8. I had an error code of 1 Please let me know if there is anything else that I am missing that you would like me to add to this post/add in a comment! Lastly, many thanks in advance to whoever can help! ------------- LOG FILE (latest.log) ------------- (from /Users/<NAME OF USER>/cursforge/minecraft/Instances/<THE NAME OF MY EMPTY MODPACK>/logs/latest.log) (This was made after running an empty modpack with same versions for all apps) ("[REDACTED]" is not the actual text from the log, it is me replacing text I figured wouldn't be necessary for fixing and would hurt my privacy) https://pastebin.com/hxXvGGEK ------------- DEBUG.LOG (I realized that I should have put this here first after I had done all of the work on putting latest.log in) -------------------- (again, "[REDACTED]" is not the actual text from the log, it is me replacing text I figured wouldn't be necessary for fixing and would hurt my privacy) https://pastebin.com/Fmh8GHYs
    • Pastebin... https://pastebin.com/Y3iZ85L5   Brand new profile, does not point to a mod as far as I can tell, my fatal message just has something about mixins. Don't know much about reading logs like this, but am genuinely stuck, please help. Java updated, pc restarted.
    • I was playing minecraft, forge 47.3.0 and 1.20.1, but when i tried to play minecraft now only crashes, i need help please. here is the crash report: https://securelogger.net/files/e6640a4f-9ed0-4acc-8d06-2e500c77aaaf.txt
  • Topics

×
×
  • Create New...

Important Information

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