Jump to content

Recommended Posts

Posted

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?

Posted

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.

 

Posted

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?

Posted

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.

Posted

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

Posted

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.

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.