Jump to content

Negating Fall Damage whilst holding item


GravityWolf

Recommended Posts

Ok, so when my item is right clicked, it sends the player launching in the direction they are looking. (Thank you hydroflame :D) This would be fine, but, however, if the player is in survival mode, they, of course, take massive amounts of fall damage. So, this is what I tried doing (yes, I do have the fallDistance variable):

 

@Override
public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) {

	player.motionY = 0.7;
	double calculatedX = 10 * (double) (-MathHelper.sin(player.rotationYaw/ 180.0F * (float) Math.PI)* MathHelper.cos(player.rotationPitch / 180.0F* (float) Math.PI) * 0.4f);
	double calculatedZ = 10 * (double) (MathHelper.cos(player.rotationYaw	/ 180.0F * (float) Math.PI)* MathHelper.cos(player.rotationPitch / 180.0F* (float) Math.PI) * 0.4f);
	double calculatedY = 10 * (double) (-MathHelper.sin((player.rotationPitch)/ 180.0F * (float) Math.PI) * 0.4f);
	player.motionY = calculatedY;
	player.motionX = calculatedX;
	player.motionZ = calculatedZ;
	player.fallDistance = 0.0f;

	return itemStack;

}

 

Of course, though, when you right click again, it just makes you fly again, adding more fallDistance, which means you always take fall damage. I'm having trouble finding a fix. If I could find a way to do a loop when holding this item (It would be OK to negate all fall damage when holding this) and continually set fall distance to 0. Of course, I have very limited Java knowledge so I do not know how to do this. If someone could help, that would be great! :D

Link to comment
Share on other sites

put this in your item class, It gets called every tick on both sides so should work:

@Override
public void onUpdate(ItemStack par1ItemStack, World par2World,
		Entity par3Entity, int par4, boolean par5) {
	super.onUpdate(par1ItemStack, par2World, par3Entity, par4, par5);
	par3Entity.fallDistance = 0;
}

 

have fun :)

Link to comment
Share on other sites

put this in your item class, It gets called every tick on both sides so should work:

@Override
public void onUpdate(ItemStack par1ItemStack, World par2World,
		Entity par3Entity, int par4, boolean par5) {
	super.onUpdate(par1ItemStack, par2World, par3Entity, par4, par5);
	par3Entity.fallDistance = 0;
}

 

have fun :)

 

Applause to you, sir! I could never figure out this kinda code on my own xD I am new to coding.

Link to comment
Share on other sites

hardly anything complicated, it's overriding a single vanilla method and adding a single line of code...

 

I would take a look at learning a bit more basic coding before you continue with modding. If you want to make anything worthwhile you will need a lot more knowledge

Link to comment
Share on other sites

hardly anything complicated, it's overriding a single vanilla method and adding a single line of code...

 

I would take a look at learning a bit more basic coding before you continue with modding. If you want to make anything worthwhile you will need a lot more knowledge

 

I'm mostly just making a mod for my server, and I really do want to learn how to be a better modder.

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.