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

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)

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.

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.

  • Author

Thank you for that hint!  I see what i did, lol and it now works!  But why would it never crash if the value I was adding was 1?  And if others want to know how i fixed it,  i forgot to check if it was null in the for loop.

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.

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.