Adityagupta Posted March 13, 2015 Posted March 13, 2015 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? Quote
Adityagupta Posted March 14, 2015 Author Posted March 14, 2015 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. Quote
Adityagupta Posted March 14, 2015 Author Posted March 14, 2015 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? Quote
gegy1000 Posted March 14, 2015 Posted March 14, 2015 Are you registering the event with the correct bus? Send your registration code for the event. Quote
Adityagupta Posted March 14, 2015 Author Posted March 14, 2015 MinecraftForge.EVENT_BUS.register(new Parachute()); Should it be on a different bus? Quote
Adityagupta Posted March 14, 2015 Author Posted March 14, 2015 The different bus worked, but I still lost health. Registering code: FMLCommonHandler.instance().bus().register(new Parachute()); How do I fix the health problem? Quote
Adityagupta Posted March 15, 2015 Author Posted March 15, 2015 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. Quote
Adityagupta Posted March 15, 2015 Author Posted March 15, 2015 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); } } Quote
Adityagupta Posted March 15, 2015 Author Posted March 15, 2015 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? Quote
Adityagupta Posted March 15, 2015 Author Posted March 15, 2015 I just tried it out, and it worked. Quote
Recommended Posts
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.