Jump to content

[Solved] Error With Particles


wiffington

Recommended Posts

Hello!  I have been working on spawning these flame particles and I have run into a problem...  I want to spawn more of them so I am trying to do this by decreasing the value in the for loop but whenever I set it below 1 it sometimes crashes when they spawn in.

 

 

When the .5 is 1 there is no crash and when its lower it sometimes crashes.

@Override
@SideOnly(Side.CLIENT)
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player){

	MovingObjectPosition objectMouseOver = player.rayTrace(5, 1);

	if(objectMouseOver != null)
	{
		for(double x = 5D;x>0D;x = x-.5){	
			world.spawnParticle("flame", objectMouseOver.blockX+(Math.random()), (objectMouseOver.blockY+.75D)+(Math.random()), objectMouseOver.blockZ+(Math.random()), 0.0D, 0.0D, 0.0D);
			System.out.println(x);
			objectMouseOver = player.rayTrace(x, 1);

		}
	}	


		return stack;
    }

 

 

Crash Report

---- Minecraft Crash Report ----

// My bad.

 

Time: 7/12/16 9:56 PM

Description: Unexpected error

 

java.lang.NullPointerException: Unexpected error

at com.example.examplemod.ItemStar.onItemRightClick(ItemStar.java:50)

at net.minecraft.item.ItemStack.useItemRightClick(ItemStack.java:164)

at net.minecraft.client.multiplayer.PlayerControllerMP.sendUseItem(PlayerControllerMP.java:430)

at net.minecraft.client.Minecraft.func_147121_ag(Minecraft.java:1557)

at net.minecraft.client.Minecraft.runTick(Minecraft.java:2044)

at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1039)

at net.minecraft.client.Minecraft.run(Minecraft.java:962)

at net.minecraft.client.main.Main.main(Main.java:164)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)

at java.lang.reflect.Method.invoke(Unknown Source)

at net.minecraft.launchwrapper.Launch.launch(Launch.java:135)

at net.minecraft.launchwrapper.Launch.main(Launch.java:28)

at net.minecraftforge.gradle.GradleStartCommon.launch(Unknown Source)

at GradleStart.main(Unknown Source)

Link to comment
Share on other sites

Is the method

onItemRightClick

marked as

@SideOnly(Side.CLIENT)

in the Item class?

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

It is not, I tried removing it but it still crashes sometimes with the same crash report.

 

Well of course it still crashes.

 

Inside the loop you're doing a raytrace at increasingly shorter distances.  What do you think happens when that raytrace doesn't hit something?

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

If the raycast hits with distance 5, then its guaranteed to hit if the distance is 6 instead.

 

However, it is not guaranteed to hit if the distance is 4...

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.