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

I am fairly new to making mods, and I am making an item that launches you up and sends you launching in the direction you are looking. Here is the code I am currently using to make the player launch up when they right click with the item:

 

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

	player.motionY = 0.7;
	return itemStack;

}

 

Any ideas? Thanks!

my teleport spell uses thsi

 

 

double motionX = 20 * (double) (-MathHelper.sin(player.rotationYaw/ 180.0F * (float) Math.PI)* MathHelper.cos(player.rotationPitch / 180.0F* (float) Math.PI) * f);
	double motionZ = 20 * (double) (MathHelper.cos(player.rotationYaw	/ 180.0F * (float) Math.PI)* MathHelper.cos(player.rotationPitch / 180.0F* (float) Math.PI) * f);
	double motionY = 20 * (double) (-MathHelper.sin((player.rotationPitch)/ 180.0F * (float) Math.PI) * f);

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

  • Author

my teleport spell uses thsi

 

 

double motionX = 20 * (double) (-MathHelper.sin(player.rotationYaw/ 180.0F * (float) Math.PI)* MathHelper.cos(player.rotationPitch / 180.0F* (float) Math.PI) * f);
	double motionZ = 20 * (double) (MathHelper.cos(player.rotationYaw	/ 180.0F * (float) Math.PI)* MathHelper.cos(player.rotationPitch / 180.0F* (float) Math.PI) * f);
	double motionY = 20 * (double) (-MathHelper.sin((player.rotationPitch)/ 180.0F * (float) Math.PI) * f);

 

On "* f" It gives me an error, are you using a variable that you had or something? It crashes when I use the item.

lolol, yes, its technily 0.4f but you could tottally remove it and it wouldnt change anything

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

  • Author

lolol, yes, its technily 0.4f but you could tottally remove it and it wouldnt change anything

 

Hmm..I put it in my onItemRightclick method and it does nothing...here is this code:

 

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

	player.motionY = 0.7;
	double motionX = 20 * (double) (-MathHelper.sin(player.rotationYaw/ 180.0F * (float) Math.PI)* MathHelper.cos(player.rotationPitch / 180.0F* (float) Math.PI) * 0.4f);
	double motionZ = 20 * (double) (MathHelper.cos(player.rotationYaw	/ 180.0F * (float) Math.PI)* MathHelper.cos(player.rotationPitch / 180.0F* (float) Math.PI) * 0.4f);
	double motionY = 20 * (double) (-MathHelper.sin((player.rotationPitch)/ 180.0F * (float) Math.PI) * 0.4f);

	return itemStack;

}

 

Sorry about my noobishness, I am new to modding like I said  :P

 

Edit: Is Pi already in Eclipse/Forge/Minecraft, or is it another class you have? Same with MathHelper.

new to coding ?

 

ok lets take it step by step

 

double motionX = 20 * (double) (-MathHelper.sin(player.rotationYaw/ 180.0F * (float) Math.PI)* MathHelper.cos(player.rotationPitch / 180.0F* (float) Math.PI) * 0.4f);
	double motionZ = 20 * (double) (MathHelper.cos(player.rotationYaw	/ 180.0F * (float) Math.PI)* MathHelper.cos(player.rotationPitch / 180.0F* (float) Math.PI) * 0.4f);
	double motionY = 20 * (double) (-MathHelper.sin((player.rotationPitch)/ 180.0F * (float) Math.PI) * 0.4f);

 

so heres my code, basicly it will calculate the translation on all 3 different axis

 

double motionX = 3;
double motionY = 3;
double motionZ = 3;

 

so this code would technicly tell the program

"yo btw i have 3 variable, one called motionX and value of 3, one called motionY and value of 3 and a last one called motionZ and value of 3"

 

now this does NOTHIGN on its own because all it says is  "hey i have these values" it doesnt do anythign with them

 

now lets take a look at your line of code

player.motionY = 0.7;

basicly this is saying to the program

"btw buddy, can you take the "player" and take a look at its "motionY" value, and while you're there can you assign it the value of 0.7"

 

now im going to write one of the 3 lines requires to make this work and youll write the 2 other

 

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

	player.motionY = 0.7;
	double calculatedX= 20 * (double) (-MathHelper.sin(player.rotationYaw/ 180.0F * (float) Math.PI)* MathHelper.cos(player.rotationPitch / 180.0F* (float) Math.PI) * 0.4f);
	double calculatedZ = 20 * (double) (MathHelper.cos(player.rotationYaw	/ 180.0F * (float) Math.PI)* MathHelper.cos(player.rotationPitch / 180.0F* (float) Math.PI) * 0.4f);
	double calculatedY = 20 * (double) (-MathHelper.sin((player.rotationPitch)/ 180.0F * (float) Math.PI) * 0.4f);
	 player.motionY = calculatedY;
                 //another line of code for another axis
                 //another line of code for the last axis

	return itemStack;

}

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

  • Author

Lol I feel like such a noob...says calculated(x y and z) cannot be resolved to a variable xD I am trying to get better

look at my secodn code, notice [glow=red,2,300]the variable names[/glow] ive change them to make thigns clearer

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

  • Author

look at my secodn code, notice [glow=red,2,300]the variable names[/glow] ive change them to make thigns clearer

 

Thank you sooooooooo much!!! Applause for you!  :D Works perfectly! Now how to figure out how to negate fall damage! xD

to negate fall damage do this: (based on hydro's code)

 

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

 

 

double calculatedX= 20 * (double) (-MathHelper.sin(player.rotationYaw/ 180.0F * (float) Math.PI)* MathHelper.cos(player.rotationPitch / 180.0F* (float) Math.PI) * 0.4f);

double calculatedZ = 20 * (double) (MathHelper.cos(player.rotationYaw / 180.0F * (float) Math.PI)* MathHelper.cos(player.rotationPitch / 180.0F* (float) Math.PI) * 0.4f);

double calculatedY = 20 * (double) (-MathHelper.sin((player.rotationPitch)/ 180.0F * (float) Math.PI) * 0.4f);

 

          player.fallDamage = 0.0F;

               

          player.motionY = calculatedY;

                //another line of code for another axis

                //another line of code for the last axis

 

return itemStack;

 

}

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.