I'm trying to store mobs inside an item using compounds. To write the mob into compound I use:
mob.addAdditionalSaveData(compound);
When all data is stored in the item I use this to discard it.
mob.discard()
The compound also stores the mobs resource location and I use this to spawn and set the data:
// Resource location stored in entity tag.
EntityType<?> type = ForgeRegistries.ENTITIES.getValue(new ResourceLocation(stack.getOrCreateTag().getString("entity")));
// I use this to get the entity. I'm using 'MobSpawnType.BUCKET' which may not be correct, if so please inform me what else to use.
Entity entity = type.spawn(level, stack, null, pos, MobSpawnType.BUCKET, true, false);
// Adding data.
((LivingEntity)entity).readAdditionalSaveData(stack.getOrCreateTag().getCompound("data"));
// Spawning
level.addFreshEntity(entity);
When spawning the logger outputs for example:
UUID of added entity already exists: Horse['Horse'/128, l='ServerLevel[Test World]', x=-93.50, y=72.00, z=52.50]
And the UUID always increments with 2 so if I summon it again it would say 'Horse'/130, 'Horse'/132, 'Horse'/134 etc.
How can I prevent this?