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 a question regarding spawning custom particles (EntityFX) on item press.

I created an EntityFX class, and it works just fine. F.e., when I use it in randomDisplayTick in a block, it looks as supposed, etc.

However, what I want to use it for is spawning particles above any block that was clicked with an item that I created. This is where the game crashes. Not instantly, though, but when i keep RMB pressed on the ground for a few seconds while holding my item,  the particles keep spawning and disappearing, but sometimes the game crashes. I tried decreasing the spawn rate of these particles, making them spawn on every fourth onItemUse call, but it still crashes. Here is the full error log:

https://gist.github.com/anonymous/c44c3b0f264fa6b970bb

 

I just can't figure out why it is crashing, so any help would be appreciated.

 

Here is the EntityFX code:

https://gist.github.com/anonymous/5557e2a1617641b13405

  • Author

Alright, I fixed it. Leaving this thread here, so that anybody with a similar issue can refer to it.

I reread the error log again, carefully, and found out that what was causing the issue was this code:

this.motionX = rand.nextFloat() * 0.1F;
this.motionY = rand.nextFloat() * 0.1F;
this.motionZ = rand.nextFloat() * 0.1F;

this.prevPosX = this.posX;
this.prevPosY = this.posY;
this.prevPosZ = this.posZ;

if (this.particleAge++ >= this.particleMaxAge)
	this.setDead();

this.moveEntity(this.motionX, this.motionY, this.motionZ);

Particularly, the moveEntity method. You can see it on lines 134 and 135 in the error log:

java.lang.NullPointerException: Ticking entity
	at net.minecraft.entity.Entity.moveEntity(Entity.java:735)

Apparently, this method has some issues when it receives random doubles as arguments, and it sometimes crashes.

 

Fixed it even more, by doing this:

this.motionX = rand.nextDouble() * 0.1D;
this.motionY = rand.nextDouble() * 0.1D;
this.motionZ = rand.nextDouble() * 0.1D;

Looks like Java really does not like float to double conversion, and when I stopped using floats, it all stopped crashing. Never mix up your primitive types!

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.