The Meaning of Life, the Universe, and Everything.
Join Date:
5/28/2014
Posts:
285
Location:
USA
Minecraft:
TheUnderTaker11
Member Details
I have wasted about 8 hours of my life at this point so i'm making a thread, I can't figure out how to get creative flight to turn of, first i wanted a chestplate to give it while you have it on, which i did correctly may i add, but I can not get the flight to turn off.
I have a tried a few things but here is an event handler attempt i made
(I did it on an item in the players inventory because if i can figure out how to do that the armor will be very similar, just changing to the getarmor thing
Click here, sorry idk how to make the code show up all fancy in this screen
There is the code that SHOULD but doesnt turn off flight, and below that is what turns on the flight
(yes i know 0 is the boots, its just testing)
Rollback Post to RevisionRollBack
Want a mod with the best magnets available? The download Better Magnets!
And if you like Avaritia then you will love More Avaritia! Adds recipes for creative items from a huge list of mods, and even adds more custom items that fit the Avaritia theme!
if (event.player.inventory.armorItemInSlot(0) == null && event.player.inventory.armorItemInSlot(0).getItem() != MyModItems.silverBoots)
this seems to be a problem, not sure if it's the whole problem thought. You check if the armor slot is empty AND if there is an item in there that isn't your flight item. The && needs to be an or, i think it's | or || in java.
The Meaning of Life, the Universe, and Everything.
Join Date:
5/28/2014
Posts:
285
Location:
USA
Minecraft:
TheUnderTaker11
Member Details
My java knowledge is, well rough to put it nicely, i do have a book a bazillion pages long ive been reading but that && just didn't catch my eye(I had copied and modified that line of code a bit) and || is or in java, but even with that change it is still not working, i will try removing one of the statements and testing then get back if that works.
[UPDATE] Removing the null part of it didnt work, and im not stupid enough to try and remove the other part to see.
Want a mod with the best magnets available? The download Better Magnets!
And if you like Avaritia then you will love More Avaritia! Adds recipes for creative items from a huge list of mods, and even adds more custom items that fit the Avaritia theme!
getItem() gives you an instance of an item while MyModItems.silverBoots seems to be a class (not sure since I can't see the code of that). In the code that turns flying on you use equals which seems to work. Try putting that in there:
if (event.player.inventory.armorItemInSlot(0) == null || !player.getCurrentArmor(0).getItem().equals(MyModItems.silverBoots))
The first part stays the same but i negated the second part with !. Also I'm not quite sure if you need the if-statement that checks if the player is not null because a PlayerTickEvent should always have a player but it shouldn't make a difference for testing.
If it still doesn't work try putting outputs before and in every if-statement, run it and you can see if it even manages to get into the statement. If not then the condition is wrong and needs work.
The Meaning of Life, the Universe, and Everything.
Join Date:
5/28/2014
Posts:
285
Location:
USA
Minecraft:
TheUnderTaker11
Member Details
ok 1 the !player had to be !event.player, the if(event.player !=null) was not needed, and I FORGOT TO RE-REGISTER MY EVENT
let me explain, earlyer i had been trying and it kept crashing my game, so i did // on the lines that had anything to do with it, and i thought i had deleted them all but i forgot to put back in the lines that register the events.
Luckily i caught it before we got to far in, jesus. That suggestion you had the first time might of worked if i registered it
(But dont worry i know the one i made a forum thread about didnt)
Lastly, just for the record, the boots dont have their own class
Thank you for your help!
Rollback Post to RevisionRollBack
Want a mod with the best magnets available? The download Better Magnets!
And if you like Avaritia then you will love More Avaritia! Adds recipes for creative items from a huge list of mods, and even adds more custom items that fit the Avaritia theme!
I'm glad it works now. Don't worry about forgetting to register it, happens sometimes and we would have caught it in the next step when the output wouldn't be there.
the error is on if (event.player.inventory.armorItemInSlot(0) == null
First, its labled 1.7.10 so yes, second, don't revive dead post if at all possible, third, Paste you code using the "Insert a code block" right next to the smiley face on the right, code like that is so annoying to read.
Now to the actual code, a have a few things to say.
What error are you getting? Not telling us the error isn't to helpful
Also, the way that code is written, doesn't take into account other mods might give you flight. The best way to do this is make a list(Java list), and any player where your armor that makes them fly is put on the list. Every tick, check if they are not wearing the armor, and if they are not then say
if player is in list
{
remove flight
remove them from list
}
This makes it so it doesnt disable flight every tick even if they have another mods flight going.
You didn't check if they were in creative to, so RIP gamemode 1 flight
td;lr: Your code doesn't check for creative or account for other mods flight.
Want a mod with the best magnets available? The download Better Magnets!
And if you like Avaritia then you will love More Avaritia! Adds recipes for creative items from a huge list of mods, and even adds more custom items that fit the Avaritia theme!
I have wasted about 8 hours of my life at this point so i'm making a thread, I can't figure out how to get creative flight to turn of, first i wanted a chestplate to give it while you have it on, which i did correctly may i add, but I can not get the flight to turn off.
I have a tried a few things but here is an event handler attempt i made
(I did it on an item in the players inventory because if i can figure out how to do that the armor will be very similar, just changing to the getarmor thing
Click here, sorry idk how to make the code show up all fancy in this screen
There is the code that SHOULD but doesnt turn off flight, and below that is what turns on the flight
(yes i know 0 is the boots, its just testing)
Want a mod with the best magnets available? The download Better Magnets!
And if you like Avaritia then you will love More Avaritia! Adds recipes for creative items from a huge list of mods, and even adds more custom items that fit the Avaritia theme!
if (event.player.inventory.armorItemInSlot(0) == null && event.player.inventory.armorItemInSlot(0).getItem() != MyModItems.silverBoots)
this seems to be a problem, not sure if it's the whole problem thought. You check if the armor slot is empty AND if there is an item in there that isn't your flight item. The && needs to be an or, i think it's | or || in java.
My java knowledge is, well rough to put it nicely, i do have a book a bazillion pages long ive been reading but that && just didn't catch my eye(I had copied and modified that line of code a bit) and || is or in java, but even with that change it is still not working, i will try removing one of the statements and testing then get back if that works.
[UPDATE] Removing the null part of it didnt work, and im not stupid enough to try and remove the other part to see.
Want a mod with the best magnets available? The download Better Magnets!
And if you like Avaritia then you will love More Avaritia! Adds recipes for creative items from a huge list of mods, and even adds more custom items that fit the Avaritia theme!
Now having sleept I see an error in exactly that other part.
getItem() gives you an instance of an item while MyModItems.silverBoots seems to be a class (not sure since I can't see the code of that). In the code that turns flying on you use equals which seems to work. Try putting that in there:
The first part stays the same but i negated the second part with !. Also I'm not quite sure if you need the if-statement that checks if the player is not null because a PlayerTickEvent should always have a player but it shouldn't make a difference for testing.
If it still doesn't work try putting outputs before and in every if-statement, run it and you can see if it even manages to get into the statement. If not then the condition is wrong and needs work.
ok 1 the !player had to be !event.player, the if(event.player !=null) was not needed, and I FORGOT TO RE-REGISTER MY EVENT
let me explain, earlyer i had been trying and it kept crashing my game, so i did // on the lines that had anything to do with it, and i thought i had deleted them all but i forgot to put back in the lines that register the events.
Luckily i caught it before we got to far in, jesus. That suggestion you had the first time might of worked if i registered it
(But dont worry i know the one i made a forum thread about didnt)
Lastly, just for the record, the boots dont have their own class
Thank you for your help!
Want a mod with the best magnets available? The download Better Magnets!
And if you like Avaritia then you will love More Avaritia! Adds recipes for creative items from a huge list of mods, and even adds more custom items that fit the Avaritia theme!
I'm glad it works now. Don't worry about forgetting to register it, happens sometimes and we would have caught it in the next step when the output wouldn't be there.
quick question is this for 1.7? if it is can you help me.
this is my code
im getting an error
@Override
public void onArmorTick(World world, EntityPlayer player, ItemStack itemStack)
{
if(player.capabilities.allowFlying == false){
player.capabilities.allowFlying=true;
}
}
@SubscribeEvent
public void onLivingUpdateEvent(LivingUpdateEvent event)
{
if (event.entityLiving != null)
{
if(event.entityLiving instanceof EntityPlayer)
{
EntityPlayer player = ((EntityPlayer)event.entityLiving);
if(player.inventory.armorItemInSlot(2) == null){
if(player.capabilities.allowFlying == true){
player.capabilities.allowFlying = false;
} if (event.player.inventory.armorItemInSlot(0) == null || !player.getCurrentArmor(0).getItem().equals(YohansWeaponsMod.HeavyDiamondChestplate)){;
if(player.capabilities.allowFlying == true){
player.capabilities.allowFlying = false;
}
}
}
}
}
}
}
the error is on if (event.player.inventory.armorItemInSlot(0) == null
First, its labled 1.7.10 so yes, second, don't revive dead post if at all possible, third, Paste you code using the "Insert a code block" right next to the smiley face on the right, code like that is so annoying to read.
Now to the actual code, a have a few things to say.
What error are you getting? Not telling us the error isn't to helpful
Also, the way that code is written, doesn't take into account other mods might give you flight. The best way to do this is make a list(Java list), and any player where your armor that makes them fly is put on the list. Every tick, check if they are not wearing the armor, and if they are not then say
This makes it so it doesnt disable flight every tick even if they have another mods flight going.
You didn't check if they were in creative to, so RIP gamemode 1 flight
td;lr: Your code doesn't check for creative or account for other mods flight.
Want a mod with the best magnets available? The download Better Magnets!
And if you like Avaritia then you will love More Avaritia! Adds recipes for creative items from a huge list of mods, and even adds more custom items that fit the Avaritia theme!