Jump to content

[1.12.2] Creative flight in survival not resetting fall distance


Recommended Posts

Posted

I have made a custom perk system (somewhat) and one of the things is creative flight. However, when using the creative flight the fall distance is not reset to zero. My guess is it is something to do with me not being smart.

 

Relevant file:

PerkHandler,java

 

package merthew.mod.util.handlers;

import merthew.mod.capability.perks.IPerks;
import merthew.mod.capability.perks.PerksProvider;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.MobEffects;
import net.minecraft.potion.PotionEffect;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;

public class PerkHandler {
	
	@SubscribeEvent
	public void perkEffects(TickEvent.PlayerTickEvent event) {
		EntityPlayer player = event.player;
		IPerks perks = player.getCapability(PerksProvider.PERKS, null);
		if(perks != null) {
			//Fly========================================================================================\\
			boolean fly = false;
			if(perks.getPerk("fly") >= 1) {
				fly = true;
				event.player.fallDistance = 0.0f;
			}
			else {
				fly = false;
			}
			
			if(fly || event.player.isCreative() || event.player.isSpectator()) {
				event.player.capabilities.allowFlying = true;
				event.player.fallDistance = 0.0f;
			}
			else {
				fly = false;
				event.player.capabilities.allowFlying = false;
				event.player.capabilities.isFlying = false;
			}
			//Strength========================================================================================\\
			if(perks.getPerk("strength") > 0) {
				player.addPotionEffect(new PotionEffect(MobEffects.STRENGTH, 10, perks.getPerk("strength"), false, false));
			}
		}
	}

}

 

The seven became one and the one became two.

Posted

Don’t Stringly type your code. How do you know the fall distance isn’t reset to 0? Have you tried stepping through your code with the debugger and seeing what happens?

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted (edited)

I put a sysout statement at the end of the method and it would read 0.0 when the player was either not moving or just moving on the horizontal axis. However, when vertical motion happened it would keep the last value and add to it. That and the player takes fall damage anytime they land if they flew above 3 or 4 blocks.

Edited by Merthew

The seven became one and the one became two.

Posted

Step through the code with the debugger and see why the player gets hurt

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted

I don't need to know why the player gets hurt, i know that it is from fall damage. I need to know why the value for fall damage is getting saved somewhere and reintroduced after i try and set it to zero.

The seven became one and the one became two.

Posted
1 hour ago, Merthew said:

I need to know why the value for fall damage is getting saved somewhere and reintroduced after i try and set it to zero.

The easiest way to do that would be to step through the code in the debugger.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted

I am just going to try to do it a different way, i have been looking at this for way too long and finding nothing. Thanks for your help though.

The seven became one and the one became two.

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.