I made some armor that I want to give fly mode to. I do use Minecraft Forge as in the title, but I am not sure how to apply flying abilities to the armor. (I do know "Minecraft.thePlayer.capabilities.allowFlying = T or F" but I don't know how to use it.)
The Meaning of Life, the Universe, and Everything.
Location:
Somewhere
Join Date:
11/29/2012
Posts:
619
Location:
Australia
Minecraft:
The_SlayerMC
Member Details
i cant help with flying but i can help with normal potion effects! i used this for jumping hight and no fall damage! you can add/change it to your liking, too add more effects just put "player.addPotionEffect(new PotionEffect(Potion./**EFFECTHERE*/.getId(), 200, 10));"
for the jump one, to jump really high with no fall damage add "player.addPotionEffect(new PotionEffect(Potion.jump.getId(), 200, 10));"
i think you change the "200" OR the "10" at the end of that line, Not really sure! haha
but for no fall damage add "player.fallDistance = 0.0F;" into the method below! but its already there lol.
and for the effect to happen you have to wear all the armor! if you want you could just change the "if()" statement to the piece of armor to your liking!
you just have to add this method into you "Custom Armor.Class":
i cant help with flying but i can help with normal potion effects! i used this for jumping hight and no fall damage! you can add/change it to your liking, too add more effects just put "player.addPotionEffect(new PotionEffect(Potion./**EFFECTHERE*/.getId(), 200, 10));"
for the jump one, to jump really high with no fall damage add "player.addPotionEffect(new PotionEffect(Potion.jump.getId(), 200, 10));"
i think you change the "200" OR the "10" at the end of that line, Not really sure! haha
but for no fall damage add "player.fallDistance = 0.0F;" into the method below! but its already there lol.
and for the effect to happen you have to wear all the armor! if you want you could just change the "if()" statement to the piece of armor to your liking!
you just have to add this method into you "Custom Armor.Class":
I know how to use potion effects on armor and I have one setup already for invisibility, and thanks for your help! I'll try to see if I can play with it and make it to what I can work with (the jump potion), but if you find anything about double-tap flying or anything similar, let me know!
Im still trying to find the "double-tap Space" "fly" haha but i cant seem to!
Hey it's ok, and I've been trying hard to find the potion one at first lol. This one's a bit harder and I looked and all I found is ModLoader's version, but the onGameHook something (idk) doesn't exist for Forge. I was close to finding it but minecraftforge.net isn't loading for some reason.
So it writes "this.allowFlying" which is true/false to the NBT tagCompound "abilities" in the tag "mayfly." When the player creates their new PlayerCapabilities, it reads the "mayfly" tag to determine if the player is allowed to fly.
There's a Forge Hook "IExtendedEntityProperties" that has an interface for reading/writing tag compounds, perhaps you could overwrite the "abilities" tagCompound in the playerentity and change "this.allowFlying" to true whenever your item is equipped, save the new tagCompound, then re-read the tagCompound. You may have to re-initialize this line from Player:
public PlayerCapabilities capabilities = new PlayerCapabilities();
// try using parEntityPlayer.capbilities = new PlayerCapabilities(); or something like that when you equip your item
Like I said, I haven't tried this yet, but it might be worth a shot.
public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
{
par3EntityPlayer.setItemInUse(par1ItemStack, this.getMaxItemUseDuration(par1ItemStack));
par3EntityPlayer.capabilities.allowFlying = true;
return par1ItemStack;
}
Just tried it and I could fly in Survival mode. Just don't forget to turn it off when you stop using / unequip
A better way is to use Events. Here's what the EventHandler would look like for an item that grants flying for a certain duration only, along with comments on what each section does:
public class YourEventHandler
{
private static int flyTime = 0;
@ForgeSubscribe
public void onLivingFallEvent(LivingFallEvent event) {
// if (flyTime > 0) { event.distance = 0; } // does NOT work correctly
if (flyTime > 0) { event.setCanceled(true); } // will not take fall damage while flying
}
/*
* Use whichever Event works best for you; I used ArrowLooseEvent because
* my scroll item charges up like a bow and activates upon release.
* A list of Forge Events can be found here: http://www.minecraftforge.net/wiki/Event_Reference
*/
@ForgeSubscribe
public void onArrowLooseEvent(ArrowLooseEvent event) {
// Check that the entity is a player
if (event.entity != null && event.entity instanceof EntityPlayer) {
// Check that the item (named 'bow' in the event) being used is of the right class
if (event.bow != null && event.bow.getItem() instanceof ItemScroll) {
// Check if the item is the one that allows you to fly
if (((ItemScroll)event.bow.getItem()).getEffectType() == ItemScroll.FLY) {
// Set how long you are allowed to fly, or use a toggle instead
flyTime = ((ItemScroll)event.bow.getItem()).getDuration();
}
}
}
}
}
@ForgeSubscribe
public void onLivingUpdateEvent(LivingUpdateEvent event)
{
if (event.entity instanceof EntityPlayer)
{
EntityPlayer player = (EntityPlayer) event.entity;
ItemStack itemInUse = player.getItemInUse();
if (itemInUse != null) {
updateItems(player, itemInUse);
}
// Need to allowFlying every update or it's difficult to get off the ground
if (flyTime > 0) { --flyTime; player.capabilities.allowFlying = true; }
if (flyTime == 0 && !player.capabilities.isCreativeMode) {
player.capabilities.allowFlying = false;
player.capabilities.isFlying = false; // drops player out of sky when timer runs out <ouch!>
}
}
}
}
EDIT: One bug with that I foresee is that as long as flyTime is greater than 0, ALL entities will be immune to fall damage, because flyTime is a global variable not tied to any specific entity calling these events. So here's the new onLivingFallEvent which fixes this bug:
@ForgeSubscribe
public void onLivingFallEvent(LivingFallEvent event) {
if (event.entity != null && event.entity instanceof EntityPlayer) {
EntityPlayer player = (EntityPlayer)event.entity;
if (player.capabilities.allowFlying && flyTime > 0) {
event.setCanceled(true);
}
}
}
Animefan8888 - did you see the date of the last post? This issue has long since been solved, but thanks anyway! The method you use has already been mentioned.
Check if armor is in the armor slot, If so, set fly to true.
I feel like no one reads the rest of the thread, nor reads the dates. This was solved last year. The thread is finished. No need to give further advice.
Rollback Post to RevisionRollBack
My IGN is gerbality, but you might see me in-game as RoseTyler.
Rather than reposting the same or similar code, let me summarize what you need to make the player fly:
1. Set player.capabilities.allowFlying to true whenever your conditions (e.g. wearing armor set) are true
2. Monitor a tick event (e.g. PlayerTickEvent) to check when the conditions are no longer met (because you cannot check in the armor tick if the armor is not worn), then set both allowFlying and isFlying to false.
That's it. All you need is a little Java knowledge, a little Minecraft / Forge knowledge, and you can be flying in a few minutes.
If you search for 'fly' in the Modification Development section, you will get plenty of results. If none of those help you figure it out on your own, it is much better to post your own topic with your specific code that you are trying rather than hijacking a year-old thread.
I made some armor that I want to give fly mode to. I do use Minecraft Forge as in the title, but I am not sure how to apply flying abilities to the armor. (I do know "Minecraft.thePlayer.capabilities.allowFlying = T or F" but I don't know how to use it.)
Thank You!
~Weasel
~Weasel
for the jump one, to jump really high with no fall damage add "player.addPotionEffect(new PotionEffect(Potion.jump.getId(), 200, 10));"
i think you change the "200" OR the "10" at the end of that line, Not really sure! haha
but for no fall damage add "player.fallDistance = 0.0F;" into the method below! but its already there lol.
and for the effect to happen you have to wear all the armor! if you want you could just change the "if()" statement to the piece of armor to your liking!
you just have to add this method into you "Custom Armor.Class":
I know how to use potion effects on armor and I have one setup already for invisibility, and thanks for your help! I'll try to see if I can play with it and make it to what I can work with (the jump potion), but if you find anything about double-tap flying or anything similar, let me know!
Anyone else who may know can help, too!
Thanks again!
~Weasel
~Weasel
Hey it's ok, and I've been trying hard to find the potion one at first lol. This one's a bit harder and I looked and all I found is ModLoader's version, but the onGameHook something (idk) doesn't exist for Forge. I was close to finding it but minecraftforge.net isn't loading for some reason.
~Weasel
~Weasel
There's a Forge Hook "IExtendedEntityProperties" that has an interface for reading/writing tag compounds, perhaps you could overwrite the "abilities" tagCompound in the playerentity and change "this.allowFlying" to true whenever your item is equipped, save the new tagCompound, then re-read the tagCompound. You may have to re-initialize this line from Player:
Like I said, I haven't tried this yet, but it might be worth a shot.
Just tried it and I could fly in Survival mode. Just don't forget to turn it off when you stop using / unequip
A better way is to use Events. Here's what the EventHandler would look like for an item that grants flying for a certain duration only, along with comments on what each section does:
public void onArmorTickUpdate(World world, EntityPlayer player, ItemStack itemStack) {
if (player.getCurrentItemOrArmor(4) != null && player.getCurrentArmor(3) != null && player.getCurrentItemOrArmor(2) != null && player.getCurrentItemOrArmor(1) != null) {
ItemStack helmet = player.getCurrentItemOrArmor(4);
ItemStack plate = player.getCurrentItemOrArmor(3);
ItemStack legs = player.getCurrentItemOrArmor(2);
ItemStack boots = player.getCurrentItemOrArmor(1);
if (helmet.getItem() == yourmodsmainclass.thehelmetyouwant&& plate.getItem() == yourmodsmainclass.thechestplateyouwant&& legs.getItem() == yourmodsmainclass.thelegsyouwant&& boots.getItem() == yourmodsmainclass.thebootsyouwant)
{
player.fallDistance = 0.0F;
player.capabilities.allowFlying = true;
}
}
}
and if you put player.capabilities.setFlySpeed(2.0F);
you can change the flying speed
I feel like no one reads the rest of the thread, nor reads the dates. This was solved last year. The thread is finished. No need to give further advice.
I'm a cat.
I needed to give the player with Zeus's Lightning Bolt the ability to fly.
What I've managed to get it to do is if the player is holding the item + right clicks + jumps,
he will be flying in survival mode. The only way to land is the hit the ground, which gives you damage.
I'm sure you could add this to your minecraft armor code.
Below is the source code..... --->
I tried this but I couldnt get it to work
Download Mod Here
Ok, i've finally managed to get this working...
So what I've made is a system where it tests whether your wearing
the armor and your in survival.
it then treats you like your in creative although you will not take fall damage from hitting the ground.
it is similar to what is above this only I had to com up with this myself.
You should put this in your armor class.
Only take from the BOLD text.
~ Here it is...
@Override
public void onArmorTick(World world, EntityPlayer player, ItemStack itemstack) {
// Checks if you are wearing the entire body of armor, remove sections of statement below to get your result.
if(player.getCurrentArmor(3) != null && player.getCurrentArmor(2) != null && player.getCurrentArmor(1) != null && player.getCurrentArmor(0) != null){
ItemStack helmet = player.getCurrentArmor(3);
ItemStack chestplate = player.getCurrentArmor(2);
ItemStack leggings = player.getCurrentArmor(1);
ItemStack boots = player.getCurrentArmor(0);
if(helmet.getItem() == yourmodsmainclass.thehelmetyouwant && chestplate.getItem() == yourmodsmainclass.thechestplateyouwant && leggings.getItem() == yourmodsmainclass.theleggingsyouwant && boots.getItem() == yourmodsmainclass.thebootsyouwant) {
player.capabilities.allowFlying = true;
player.fallDistance = 0.0f;
}
else {
player.capabilities.allowFlying = false;
player.capabilities.isFlying = false;
}
}
}
------------------------------------------------------------------------------------
Taken from code from my mod, The MarvelCraftUniverse Mod.
If this is helpful please check it out.
EDIT: This is what you were looking for, a double-tap flying armor.
Rather than reposting the same or similar code, let me summarize what you need to make the player fly:
1. Set player.capabilities.allowFlying to true whenever your conditions (e.g. wearing armor set) are true
2. Monitor a tick event (e.g. PlayerTickEvent) to check when the conditions are no longer met (because you cannot check in the armor tick if the armor is not worn), then set both allowFlying and isFlying to false.
That's it. All you need is a little Java knowledge, a little Minecraft / Forge knowledge, and you can be flying in a few minutes.
If you search for 'fly' in the Modification Development section, you will get plenty of results. If none of those help you figure it out on your own, it is much better to post your own topic with your specific code that you are trying rather than hijacking a year-old thread.
how to make it toggle?
I am just a viewer
I want to fly when nbt "postava" is 2, but when I join the world game crashes
only when I uncomment it