Jump to content

[1.8] Parachute Mod


Adityagupta

Recommended Posts

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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

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.