Jump to content

EntityItem onUpdate() NullPointerException


ss7

Recommended Posts

Hello,

 

I'm trying to render a

EntityItem

above a

Block

and that works, but i want it to rotate, so i call item.onUpdate() in my

updateEntity()

of my

TileEntity

. The problem is, that the game crashes with a NullPointerException, even if i check for item != null. Here is the full crash log:

 

http://gw.minecraftforge.net/BGXq

 

But when i look at the error line there is only

this.worldObj.theProfiler.startSection("entityBaseTick");

but i think that this has nothing to do with it.

 

Here is my

updateEntity()

:

 

 

if (inventory[0] != null)
	{
		enabled = worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord);
	}

	else
	{
		enabled = false;
	}

	if (item != null && enabled)
	{
		item.onUpdate();
	}

 

 

I hope you can help!

 

PS: As you can see i really like this Teletype function :P

 

ss7

You sir are a god damn hero.

Link to comment
Share on other sites

Because you're using a "fake" EntityItem that isn't added to the world, the EntityItem is causing a NPE when it attempts to access its world object (which is null):

 

public void onEntityUpdate()
    {
        this.worldObj.theProfiler.startSection("entityBaseTick");

 

It's cashing at "this.worldObj.theProfiler" because "worldObj" is null.

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

Are you sure you are not creating the Entity with a null world?

 

He totally is, because he's never spawning it in the world (he's doing the same thing I'm doing right now, except he wants it to rotate, and I don't).

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

He totally is, because he's never spawning it in the world (he's doing the same thing I'm doing right now, except he wants it to rotate, and I don't).

There is a difference between the entity having a null world and the entity not being spawned into the world. You can totally construct an entity with a valid world, but never spawn it.

 

Touche.  Just checked my code and I am setting a world object, but I suspect he isn't.

As that's the only reason that line would crash.

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

Hello,

 

And!..........You will wonder......i am giving it the

worldObj

of the

TileEntity

! So i thought the problem would be that the

TileEntity's

worldObj

is not initialized, but i made a test with a bool that is true when it initialized the EntityItem, but that's also not working.

 

It's working sometimes, but not always.

 

ss7

You sir are a god damn hero.

Link to comment
Share on other sites

I'd suggest just updating the entity's rotation/age/etc. through your TE's update, rather than calling the EntityItem's update function.

That would give you better control over the animation (e.g. rotating but not bobbing).  I'm actually using that for some animation one of of my blocks right now: tweaking the Entity's age, then using that value in the render process.

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

Hello,

 

I'm trying to adjust the

rotationYaw

of the

EntityItem

but it doesn't seem to work, it's just not rotating.

I was even looking at the

onUpdate()

method of

EntityItem

but it also set's no rotationYaw.

 

ss7

You sir are a god damn hero.

Link to comment
Share on other sites

I'm trying to adjust the

rotationYaw

of the

EntityItem

but it doesn't seem to work, it's just not rotating.

I was even looking at the

onUpdate()

method of

EntityItem

but it also set's no rotationYaw.

 

Based on some trouble I had the other day, item entity's rotation is based on age.

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

Hello,

 

OK, now i'm incrementing the item's age every tick. That works sometimes for one full 360° rotation, but then it resets to the initial rotation. I've tried setting also the rotationYaw, but that doesn't worked. How have you done that?

 

ss7

You sir are a god damn hero.

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.



×
×
  • Create New...

Important Information

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