Jump to content

Recommended Posts

Posted

I have been working on a mod that includes an entity (EntityCommoner) that responds to custom user commands. To get started, I tried to get the commoner to go to the player's position at the time the "$come" command is issued. The AI task should change state to active when this happens. Sometimes it works fine and the entity moves to the correct location. However, the task state sometimes alternates every tick between active and inactive and the entity does not move or respond, and I have no clue as to why. In the output below, should ex should either be false or true for a while, not alternating on every tick. The target coordinates alter between what they should be (the player's coordinates when the command is issued) and what they were previously, if that helps anyone.

 

Below is the relevant code and console output from a print staement in the entity's onUpdate function.

 

Command Handler

 

  Reveal hidden contents

 

 

EntityCommoner

 

  Reveal hidden contents

 

 

EntityAIGoToPosition

 

  Reveal hidden contents

 

 

some console output

 

  Reveal hidden contents

 

Posted

Don't ever store references to entities like that.  If a chunk gets unloaded and then reloaded, the entity you see is not the same as the one you've saved a reference to.

 

This is why world.getEntitiesInAABB exists.

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.

Posted
  On 8/24/2016 at 11:35 PM, Draco18s said:

Don't ever store references to entities like that.  If a chunk gets unloaded and then reloaded, the entity you see is not the same as the one you've saved a reference to.

 

This is why world.getEntitiesInAABB exists.

 

When you say store references to entities like that you are referring to the static list i am using in the EntityCommoner class?

Posted

Yes

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.

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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