Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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

  • Author

I registered it in preint as MinecraftForge.EVENT_BUS.register(new TickHandler());

But it still does not stop flying when I take the armor off.

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

  • Author

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

 

So I put that in the TickHandler Class?

  • Author

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?

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.