Posted July 21, 20169 yr 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?
July 21, 20169 yr 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. http://i.imgur.com/NdrFdld.png[/img]
July 22, 20169 yr Author 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; } }
July 22, 20169 yr Author I just realized its because forge creates a new player each time I compile and run the mod, which is generating a new UUID. If I simply leave the world without closing the client it works as intended.
July 22, 20169 yr Ah yes, I remember that confusing me as well. You can set your username in the run-time configuration so that it is always the same - it doesn't have to be your real Minecraft account, though you can use that, too. http://i.imgur.com/NdrFdld.png[/img]
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.