I am learning mod development with Forge and 1.7.2. I have created a custom Armor Chestplate, and I want to know how to enable Creative Flight while wearing it. Any help would be great, thanks.
I've tested this but I don't get it to work. I can make the player fly when he wears the armor but I can't get to disable the flying. Maybe changing the NBT?
I've tested this but I don't get it to work. I can make the player fly when he wears the armor but I can't get to disable the flying. Maybe changing the NBT?
it didn't work for me. did it work for you nixcode?
if you want this for the whole suit of armor and not just the chestplate would you have to do !=yourchestplate multiple times?
You would need to check every armor slot for allowing flight, and check all of them again until any one of them is incorrect to disable flight, at which point you can stop checking.
In logic / code terms, that's:
// for allowing flight
if (
playerHelmet != null && playerHelment.getItem() == YourMod.yourHelmet &&
playerChest != null && playerChest.getItem() == YourMod.yourChest &&
playerLegs != null && playerLegs.getItem() == YourMod.yourLegs &&
playerBoots != null && playerBoots.getItem() == YourMod.yourBoots)
) {
// success! every armor slot contains the correct armor piece!
}
// for turning flight off, you only need to find ONE incorrect piece, using either OR ||, or else/if statements
if (
playerHelmet == null || playerHelmet.getItem() != YourMod.yourHelmet // notice how it's switched from the first example
|| playerChest == null || playerChest.getItem() != YourMod.yourChest
// etc.
) {
// if any single one of those statements is true, the player is no longer wearing the full set
// disable flight UNLESS the player is in Creative Mode
}
http://www.planetminecraft.com/mod/the-iron-man-mod/
http://www.minecraftforum.net/topic/2707244-172forge-the-iron-man-mod/
The problem is that if you take the armor off, you will still be able to fly. So this could help:
If you don't know how to use Events, This could help.
I've tested this but I don't get it to work. I can make the player fly when he wears the armor but I can't get to disable the flying. Maybe changing the NBT?
http://www.planetminecraft.com/mod/the-iron-man-mod/
http://www.minecraftforum.net/topic/2707244-172forge-the-iron-man-mod/
I tried and it works perfectly to me. This is the fixed event to disable flying when you take the armor off.
If the player takes the armor in mid-air he won't fall, but the next time he touches the ground he will recieve fall damage.
http://www.planetminecraft.com/mod/the-iron-man-mod/
http://www.minecraftforum.net/topic/2707244-172forge-the-iron-man-mod/
You would need to check every armor slot for allowing flight, and check all of them again until any one of them is incorrect to disable flight, at which point you can stop checking.
In logic / code terms, that's:
http://www.planetminecraft.com/mod/the-iron-man-mod/
http://www.minecraftforum.net/topic/2707244-172forge-the-iron-man-mod/
Instead, why don't you post your code, and we'll help you figure out what's wrong with it.
on Bottom Code Is Not Read it by game
@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.isCreativeMode){
player.capabilities.allowFlying = false;
}
}else if(player.inventory.armorItemInSlot(2).getItem() != mcreator_omegaArmor.body){
if(player.capabilities.allowFlying == true && !player.capabilities.isCreativeMode){
player.capabilities.allowFlying = false;
}
}
}
}
}
help me pls, it is not working for me, this is my code
@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;
}
}else if(player.inventory.armorItemInSlot(1).getItem() != YohansWeaponsMod.HeavyDiamondChestplate){
if(player.capabilities.allowFlying == true){
player.capabilities.allowFlying = false;
}
}
}
}
}
}