Jump to content

[1.7.10][Solved] Armor Flying


Jetfan16ladd

Recommended Posts

I am attempting to make a armor that allows the player to fly in survival mode while wearing it. I have been trying to use other people questions and answers on the forums but when ever I take the armor off I can still fly.

Here is my Tick Handler Class:


public class TickHandler {

   public static Map<EntityPlayer, Boolean> playersWithFlight = new WeakHashMap<EntityPlayer, Boolean>();

   @SubscribeEvent
   public void onEntityUpdate(PlayerTickEvent event) {
if (event.phase != TickEvent.Phase.START || !event.player.worldObj.isRemote) return;

         
            System.out.println("Equipment Stack "+event.player.getEquipmentInSlot(3));
           if (event.player.getEquipmentInSlot(3) != null) System.out.println("Item "+event.player.getEquipmentInSlot(3).getItem());
           System.out.println("Target Item "+Mineturnedmain.Mark7Chestplate);

           System.out.println(event.player.getEquipmentInSlot(3) != null && event.player.getEquipmentInSlot(3).getItem() == Mineturnedmain.Mark7Chestplate);


           if (event.player.getEquipmentInSlot(3) != null && event.player.getEquipmentInSlot(3).getItem() == Mineturnedmain.Mark7Chestplate) {
         
         playersWithFlight.put(event.player, true);
         event.player.capabilities.allowFlying = true;

      } else {

         if (!playersWithFlight.containsKey(event.player)) {
            playersWithFlight.put(event.player, false);
              }

         if (playersWithFlight.get(event.player)) {
            playersWithFlight.put(event.player, false);

            if (!event.player.capabilities.isCreativeMode) {
               event.player.capabilities.allowFlying = false;
               event.player.capabilities.isFlying = false;
               event.player.sendPlayerAbilities();
            }
         }
      }
   }


}

 

Here is my Armor Class:

public class Mark7 extends ItemArmor {
    private String [] armourTypes = new String[] {"Mark7Mask", "Mark7Chestplate", "Mark7Leggings", "Mark7Boots"};


    public Mark7(ArmorMaterial armorMaterial, int renderIndex, int armourType) {
        super(armorMaterial, renderIndex, armourType);
    }

    @Override
    public String getArmorTexture(ItemStack stack, Entity entity, int slot, String layar){
        if(stack.getItem().equals(Mineturnedmain.Mark7Mask)|| stack.getItem().equals(Mineturnedmain.Mark7Chestplate)|| stack.getItem().equals(Mineturnedmain.Mark7Boots)){
            return "morecraftingmod:textures/models/armor/Mark7_1.png";
        }

        if(stack.getItem().equals(Mineturnedmain.Mark7Leggings)){
            return "morecraftingmod:textures/models/armor/Mark7_2.png"; 
        }
        else return null;
    }
    public void registerIcons(IIconRegister reg){ 
        if(this == Mineturnedmain.Mark7Mask)
            this.itemIcon = reg.registerIcon("morecraftingmod:Mark7Mask");
        if(this == Mineturnedmain.Mark7Chestplate)
            this.itemIcon = reg.registerIcon("morecraftingmod:Mark7Chestplate");
        if(this == Mineturnedmain.Mark7Leggings)
            this.itemIcon = reg.registerIcon("morecraftingmod:Mark7Leggings");
        if(this == Mineturnedmain.Mark7Boots)
            this.itemIcon = reg.registerIcon("morecraftingmod:Mark7Boots");
    }
    
    @Override
    public void onArmorTick(World world, EntityPlayer player, ItemStack itemstack){
    	
      	if(player.getCurrentArmor(3)!= null){
    		ItemStack helmet = player.getCurrentArmor(3);
    		if (helmet.getItem() == Mineturnedmain.Mark7Mask){
    			player.addPotionEffect(new PotionEffect(Potion.fireResistance.getId(), 100, 10));
    		}}
    		   	if(player.getCurrentArmor(1)!= null){
    	    		ItemStack leggings = player.getCurrentArmor(1);
    	    		if (leggings.getItem() == Mineturnedmain.Mark7Leggings){
    	    			player.addPotionEffect(new PotionEffect(Potion.damageBoost.getId(), 100, 3));
    		}
    	}
    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() == Mineturnedmain.Mark7Mask && chestplate.getItem() == Mineturnedmain.Mark7Chestplate && leggings.getItem() == Mineturnedmain.Mark7Leggings 
			&& boots.getItem() == Mineturnedmain.Mark7Boots);
	player.addPotionEffect(new PotionEffect(Potion.waterBreathing.getId(),100, 20));


    }
        if(player.capabilities.allowFlying == false){
            player.capabilities.allowFlying=true;
        }
    }
}

Link to comment
Share on other sites

Yeah, it got pasted twice. Fixed.

 

I tied TickHandler.Class but it still allows the player to fly when not wearing the armor.

That's not an instance of your class, so of course it wouldn't work. The argument is an Object, not a Class:

new TickHandler() // that creates an instance of your class, i.e. a real object that exists

Link to comment
Share on other sites

Thanks for helping me even though I am a java noob.

I took this code out of the Armor Class

if(player.capabilities.allowFlying == false){
            player.capabilities.allowFlying=true;
        }

and  everything works fine except when I fly around for a bit and land I take large amounts of fall damage. This also happens if I remove the chest plate in the air. The amount of fall damage I take is not normal or realistic. How can I fix this?

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



×
×
  • Create New...

Important Information

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