Jump to content

Recommended Posts

Posted

I have create a fair number of custom entities without any errors or oddities popping up, except for this last one.

 

I created a CopyCat mob.  Basically it will pretend to be any player that has been on the server before.  It has their skin, gear, and displays their name. 

 

Everything works fine, but I get an error on minecraft whenever this mob's dimensions is unloaded and then reloaded.  The error states the entity is in an unexpected spot 0,0,0.

 

It doesn't crash the game or stop the mob from spawning, but I can't confirm whether it destroys instances of the mob that existed before unload or not.  Its a rare spawn and I just haven't witnessed it yet.

 

The differences in the code from my others mobs are that it extends entitymob instead of something line entitycreper and I added a datawatcher. 

 

Is there something that needs to be added like telling the mob to despawn or such? 

 

I'll be happy to post the code, but I dont' know what to post because I don't think the error is in what I have.  I think it is in what I don't have.  All that is there is the stuff to make the skin and gear initiate and the datwatcher.  The rest of the class is just empty as its using the stuff extended from entitymob.

 

 

Long time Bukkit & Forge Programmer

Happy to try and help

Posted

I tried again tonight to combat this by modifying some of my setup code and strip it down.  Still getting the error.  It doesn't seem to crash the server or cause anything, but I don't like that much error spam. 

 

Anyone got an idea?

Long time Bukkit & Forge Programmer

Happy to try and help

Posted

Hate to bump this again, but I can't figure it out and I can't find anything searching like it.

Long time Bukkit & Forge Programmer

Happy to try and help

Posted

what happens when the entity is written/read from nbt?It should store its location but if you've messed that up somehow that'd explain why it thinks it is at 0, 0, 0

We need code and logs.

I do Forge for free, however the servers to run it arn't free, so anything is appreciated.
Consider supporting the team on Patreon

Posted

I'll dig some up.  That is what I was looking for was what part to grab. 

 

 

In grabbing the code, I think I see it.  Got trigger happy with the copy paste.  I'll delete the write from this and i bet it fixes it.

 

 

 

 

    @Override

    public void readFromNBT(NBTTagCompound tag) {

    //System.out.println("Reading from NBT Data");

   

    // Attempt to read custom NBT

    try {

   

    skin(tag.getString("name"));

   

    } catch(Exception e) {

   

    }

   

    // Call Parent

    super.writeToNBT(tag);

   

    // Call Parent

    super.readEntityFromNBT(tag);

   

    }   

 

 

 

 

 

Long time Bukkit & Forge Programmer

Happy to try and help

Posted

I'll dig some up.  That is what I was looking for was what part to grab. 

 

 

In grabbing the code, I think I see it.  Got trigger happy with the copy paste.  I'll delete the write from this and i bet it fixes it.

 

 

 

 

    @Override

    public void readFromNBT(NBTTagCompound tag) {

    //System.out.println("Reading from NBT Data");

   

    // Attempt to read custom NBT

    try {

   

    skin(tag.getString("name"));

   

    } catch(Exception e) {

   

    }

   

    // Call Parent

    super.writeToNBT(tag);

   

    // Call Parent

    super.readEntityFromNBT(tag);

   

    }   

 

 

 

 

 

    	// Call Parent
    	super.writeToNBT(tag);
    	
    	// Call Parent
    	super.readEntityFromNBT(tag);

 

so, I see 2 problems here: in your readFromNBT method, you call super.writeToNBT and readEntityFromNBT. The first writes the position to the NBT, which in this state is still 0,0,0. Also readEntityFromNBT doesn't read the position AFAIK, and if it does, it would read the 0,0,0 you've wrote in your previous call.

 

I suggest not to override readFromNBT/writeToNBT methods in entities but rather use the readEntityFromNBT/writeEntityToNBT, an the first call in this method is the super call to the same method.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Posted

Wow, I really messed that up.  Changing it per your suggestions and fixes.  Thank you, I've been looking at this for days and only seeing what I thought should be there.

 

A little history on it was that I started out with the read/write entity methods but changed in effort to get the name to the client.  I eventually used a datawatcher instead but never changed this back.

 

A couple questions:

  • Why the entity method verses the base one?  Had some experiences with it or does it not call get consistently?
  • In a setup like this, how could putting the super at beginning or end mess it up other than if I used the same variables in there?  But then that would mess up something either way.

 

 

This looks better?

 

 

 

 

    @Override

    public void writeEntityToNBT(NBTTagCompound tag) {

    //System.out.println("Writing to NBT Data");

   

    // Call Parent

    super.writeEntityToNBT(tag);   

   

    // Attempt to input custom NBT

    try {

   

    tag.setString("name", skin);

   

    } catch(Exception e) {

   

    }

           

    }

   

    @Override

    public void readEntityFromNBT(NBTTagCompound tag) {

    //System.out.println("Reading from NBT Data");

   

    // Call Parent

    super.readEntityFromNBT(tag);

   

    // Attempt to read custom NBT

    try {

   

    skin(tag.getString("name"));

   

    } catch(Exception e) {

   

    }   

   

    }

 

 

 

Long time Bukkit & Forge Programmer

Happy to try and help

Posted

A couple questions:

  • Why the entity method verses the base one?  Had some experiences with it or does it not call get consistently?
  • In a setup like this, how could putting the super at beginning or end mess it up other than if I used the same variables in there?  But then that would mess up something either way.

 

 

This looks better?

 

 

 

 

    @Override

    public void writeEntityToNBT(NBTTagCompound tag) {

    //System.out.println("Writing to NBT Data");

   

    // Call Parent

    super.writeEntityToNBT(tag);   

   

    // Attempt to input custom NBT

    try {

   

    tag.setString("name", skin);

   

    } catch(Exception e) {

   

    }

           

    }

   

    @Override

    public void readEntityFromNBT(NBTTagCompound tag) {

    //System.out.println("Reading from NBT Data");

   

    // Call Parent

    super.readEntityFromNBT(tag);

   

    // Attempt to read custom NBT

    try {

   

    skin(tag.getString("name"));

   

    } catch(Exception e) {

   

    }   

   

    }

 

 

 

 

  • Just convenience, also every (at least AFAIK) vanilla entity only overrides the entity one. It doesn't mess anything up if you use the other one. Just make sure on both you call the super method.
  • Just more readable and convenience. You can put it anywhere in the method, but make sure it gets called every time.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

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.