Posted January 29, 201510 yr 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; } } }
January 29, 201510 yr If you didn't register it, then yes, you do, just like any other event-watching class. TickEvents are fired on the FML bus, so register your TickHandler class on that one. http://i.imgur.com/NdrFdld.png[/img]
January 29, 201510 yr Author TickEvents are fired on the FML bus, so register your TickHandler class on that one. What is the FML bus?
January 29, 201510 yr 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.
January 29, 201510 yr That's because the MinecraftForge.EVENT_BUS is NOT the FML bus. FMLCommonHandler.instance().bus().register(yourEvents); http://i.imgur.com/NdrFdld.png[/img]
January 29, 201510 yr It says TickHandler Cannot be resolved as a varible ... sounds like you need to learn Java. http://i.imgur.com/NdrFdld.png[/img]
January 29, 201510 yr Author I tied TickHandler.Class but it still allows the player to fly when not wearing the armor.
January 29, 201510 yr Author ... sounds like you need to =http://docs.oracle.com/javase/tutorial/java/index.htmllearn Java. That link doesn't even work.
January 29, 201510 yr 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 http://i.imgur.com/NdrFdld.png[/img]
January 29, 201510 yr 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?
January 29, 201510 yr No, you use it when registering your TickEvent handling class. Look at the method requirements for FMLCommonHandler's 'register' method - it requires an Object instance be passed in, i.e. the instance of your class. http://i.imgur.com/NdrFdld.png[/img]
January 30, 201510 yr 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.