Jump to content

Recommended Posts

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!

Posted

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-

Posted

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.

Posted

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-

Posted

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.

Posted

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-

Posted

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-

Posted

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

Posted

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

×   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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I tried do download the essential mod to my mod pack but i didnt work. I paly on 1.21 and it should work. I use neoforge for my modding. The weird things is my friend somehow added the mod to his modpack and many others that I somehow can´t. Is there anything i can do? 
    • Thanks, I've now installed a slightly newer version and the server is at least starting up now.
    • i have the same issue. Found 1 Create mod class dependency(ies) in createdeco-1.3.3-1.19.2.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Found 11 Create mod class dependency(ies) in createaddition-fabric+1.19.2-20230723a.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Detailed walkthrough of mods which rely on missing Create mod classes: Mod: createaddition-fabric+1.19.2-20230723a.jar Missing classes of create: com/simibubi/create/compat/jei/category/sequencedAssembly/JeiSequencedAssemblySubCategory com/simibubi/create/compat/recipeViewerCommon/SequencedAssemblySubCategoryType com/simibubi/create/compat/rei/CreateREI com/simibubi/create/compat/rei/EmptyBackground com/simibubi/create/compat/rei/ItemIcon com/simibubi/create/compat/rei/category/CreateRecipeCategory com/simibubi/create/compat/rei/category/WidgetUtil com/simibubi/create/compat/rei/category/animations/AnimatedBlazeBurner com/simibubi/create/compat/rei/category/animations/AnimatedKinetics com/simibubi/create/compat/rei/category/sequencedAssembly/ReiSequencedAssemblySubCategory com/simibubi/create/compat/rei/display/CreateDisplay Mod: createdeco-1.3.3-1.19.2.jar Missing classes of create: com/simibubi/create/content/kinetics/fan/SplashingRecipe
    • The crash points to moonlight lib - try other builds or make a test without this mod and the mods requiring it
    • Do you have shaders enabled? There is an issue with the mod simpleclouds - remove this mod or disable shaders, if enabled  
  • Topics

×
×
  • Create New...

Important Information

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