Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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?

  • 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.

 

  • 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?

  • 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?

  • 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.

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

  • 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.

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...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.