Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.7.10] Syncing custom entity owner with clients?


Recommended Posts

My custom mob is losing its owner after I logout and back into a world.

 

public EntityCustom(World world) {
super(world);
this.setSize(0.6F, 0.8F);
_type = 0;
preventEntitySpawning = true;
this.func_110163_bv(); // forces entity to not despawn
this.getNavigator().setAvoidsWater(true);

        this.tasks.addTask(1, new EntityAISwimming(this));
        this.tasks.addTask(2, this.aiSit);
        this.tasks.addTask(3, new EntityAILeapAtTarget(this, 0.4F));
        this.tasks.addTask(4, new EntityAIAttackOnCollide(this, 1.0D, true));
        this.tasks.addTask(5, new EntityAIFollowOwner(this, 1.0D, 5.0F, 1.0F));
        this.tasks.addTask(6, new EntityAIMate(this, 1.0D));
        this.tasks.addTask(7, new EntityAIWander(this, 1.0D));
        this.tasks.addTask(9, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F));
        this.tasks.addTask(9, new EntityAILookIdle(this));
        
        this.targetTasks.addTask(1, new EntityAIOwnerHurtByTarget(this));
        this.targetTasks.addTask(2, new EntityAIOwnerHurtTarget(this));
        this.targetTasks.addTask(3, new EntityAIHurtByTarget(this, true));
        this.targetTasks.addTask(4, new EntityAITargetNonTamed(this, EntitySheep.class, 200, false));
        
        System.out.println("OWNER: " + this.getOwner() + " " + FMLCommonHandler.instance().getEffectiveSide());
}

public EntityCustom(World world, EntityPlayer player) {
this(world);
        this.setTamed(true);
        this.func_152115_b(player.getUniqueID().toString()); // sets owner
        this.worldObj.setEntityState(this, (byte)7);
        
        System.out.println("SET OWNER: " + this.getOwner() + " " + FMLCommonHandler.instance().getEffectiveSide());
} 

 

The output of those logs:

SET OWNER: EntityPlayerMP['Player54'/45, l='Copy of New World', x=261.50, y=69.00, z=317.50] SERVER
OWNER: null CLIENT

 

From what I could tell func_152115_b() sets the UUID on the datawatcher which (from what I understand) is automatically synced between the server and clients. Am I missing a step?

 

 

Link to post
Share on other sites

The second constructor is only called on the server whereas the single-World argument constructor is used on the client. There is no way to change which constructor is used on the client, but you can implement IEntityAdditionalSpawnData in your Entity class to send additional information to the client side when your entity spawns.

 

However, if the mob is actually losing the owner when you logout and not just missing it on the client, then you are not correctly saving to or reading from NBT. Show those methods.

Link to post
Share on other sites

I've extended the EntityTameable class, so the methods I'm using are the ones found in there. I had assumed they were setup to sync since other classes do nothing extra. Here they are anyway:

 

public void func_152115_b(String p_152115_1_)
{
     this.dataWatcher.updateObject(17, p_152115_1_);
}

public EntityLivingBase getOwner()
{
     try
     {
         UUID uuid = UUID.fromString(this.func_152113_b());
         return uuid == null ? null : this.worldObj.func_152378_a(uuid);
     }
     catch (IllegalArgumentException illegalargumentexception)
     {
         return null;
     }
}

Link to post
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.

Guest
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 Privacy Policy.