Posted March 13, 201510 yr Hi Everybody, I am making a simple mod that deploys a parachute whenever the player is sneaking, but I can't get it to negate fall damage. My code is as follows: package org.devoxx4kids.forge.mods; import net.minecraft.entity.player.EntityPlayer; import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; public class Parachute { @SubscribeEvent public void deployParachute(LivingUpdateEvent event) { if (!(event.entity instanceof EntityPlayer)) { return; } if (!((EntityPlayer) event.entity).isAirBorne || !((EntityPlayer) event.entity).isSneaking()) { return; } event.entity.motionY = -0.05; event.entity.fallDistance = -10; } } The "event.entity.fallDistance = -10" line is for negating damage, but it doesn't work. Can someone tell me what I am doing wrong?
March 14, 201510 yr Author I registered the event handler, and fall distance to 0 didn't work either. Also, PlayerTickEvent doesn't work, but the way I did it, the fall speed is lowered, but the fall damage is not.
March 14, 201510 yr Author My code is as follows: @SubscribeEvent public void deployParachute(PlayerTickEvent event) { EntityPlayer player = event.player; if (!player.isAirBorne || !player.isSneaking()) { return; } player.motionY = -0.05; player.fallDistance = 0; } With this code, the parachute doesn't even deploy when I press shift in the air. What am I doing wrong?
March 14, 201510 yr Are you registering the event with the correct bus? Send your registration code for the event.
March 14, 201510 yr Author MinecraftForge.EVENT_BUS.register(new Parachute()); Should it be on a different bus?
March 14, 201510 yr Author The different bus worked, but I still lost health. Registering code: FMLCommonHandler.instance().bus().register(new Parachute()); How do I fix the health problem?
March 15, 201510 yr Author I tried a bunch of things - canceling the LivingFallEvent, setting its distance to 0, healing the entity, and even LivingHurtEvent with DamageSource as fall, but none of them worked.
March 15, 201510 yr Author My code: //package org.devoxx4kids.forge.mods; // //import net.minecraft.entity.player.EntityPlayer; //import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent; //import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; // //public class Parachute { // @SubscribeEvent // public void deployParachute(LivingUpdateEvent event) { // if (!(event.entity instanceof EntityPlayer)) { // return; // } // if (!((EntityPlayer) event.entity).isAirBorne // || !((EntityPlayer) event.entity).isSneaking()) { // return; // } // event.entity.motionY = -0.05; // event.entity.fallDistance = -10; // } //} package org.devoxx4kids.forge.aods; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.DamageSource; import net.minecraftforge.event.entity.living.LivingFallEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent.PlayerTickEvent; public class Parachute { @SubscribeEvent public void deployParachute(PlayerTickEvent event) { EntityPlayer player = event.player; if (!player.isAirBorne || !player.isSneaking()) { return; } player.motionY = -0.05; player.fallDistance = 0; } @SubscribeEvent public void negateFallDamage(LivingFallEvent event) { if (!(event.entity instanceof EntityPlayer)) { return; } EntityPlayer player = (EntityPlayer) event.entity; if (!player.isSneaking()) { return; } event.setCanceled(true); } }
March 15, 201510 yr Author I think I know what's happening: The FMLCommonHandler bus registers the PlayerTickEvent, but I need the EVENT_BUS one for the LivingFallEvent. Should I register the class with both of the buses?
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.